Reputation: 1317
We have a React App built on top of firebase. The problem we are facing is if you change the url by navigating to a different page other than the root '/'
, then refresh the page, it displays a 404
as seen below. But this only happens in production.
my firebase.json
look like the following:
{
"firestore": {
"rules": "firestore.rules",
"indexes": "firestore.indexes.json"
},
"hosting": {
"public": "build",
"ignore": ["firebase.json", "**/.*", "**/node_modules/**"]
},
"storage": {
"rules": "storage.rules"
},
"functions": {
"predeploy": ["npm --prefix \"$RESOURCE_DIR\" run lint"]
}
}
and we are using react-router
for navigation.
<Routes>
<Route path='/' element={<Home />} />
<Route path='/registration' element={<Registration />} />
...
</Routes>
Upvotes: 0
Views: 509
Reputation: 191
You will need to include this in your firebase.json.
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
Upvotes: 1