React Router - Content disappear on refresh (client route access)#
Issue - React Router is client side routing and when a url is requested to server, it has no such route.
Discussion#
Fixes#
- HashRouter - has # before all routes, clever hack, ugly and issues with google console redirect url.
- Express server to distribute static assets.
- …alot more here for webpack on dev servers, apache server.
Usabe Fixes#
- _redirects file on public folder with following content.
worked on netlify
Vendor specific solutions
Netlify
netlify.toml file on root directory with the following content:
1
2
3
4
5
| [[redirects]]
from = "/*"
to = "/index.html"
status = 200
force = false
|
reference
Vercel
vercel.json file on root directory with the following content:
1
2
3
| {
"rewrites": [{ "source": "/(.*)", "destination": "/index.html" }]
}
|
reference
Firebase
firebase.json file on root directory with the following content:
1
2
3
4
5
6
7
8
9
10
| {
"hosting": {
"rewrites": [
{
"source": "*",
"destination": "/index.html"
}
]
}
}
|
reference