Reputation: 527
I am getting a 404 error from my vercel deployment of flutter web project. The error has a link which redirects me to this url.
I get the error when I try to access a route www.foobar.com/post/123456
.
I am using go router for my project. And the build command is as follows:
flutter build web --web-renderer canvaskit --dart-define=BROWSER_IMAGE_DECODING_ENABLED=false --release
Most of the flags in the build command is necessary for my project. What might be the issue and how to solve it?
The initial route which is "/" loads without any issue. The problem only happens when I try to navigate to any other route
Upvotes: 3
Views: 1184
Reputation: 2946
For single page apps you'll have to return the index.html for all URLs.
You can do this by configuring rewrites in your vercel.json config.
Here's how it looks like in my vercel.json for example:
{
"version": 2,
"name": "myappname",
"rewrites": [
// rewrite all URLs to "/" which will serve the index.html
// if you have more rewrites then put them above this one
{"source": "/:a*", "destination": "/"}
]
}
Upvotes: 7