I have a react app that uses react-router with a Router that looks like:
<Router>
<div>
<Route exact path="/" component={Homepage} />
<Route path="/map/:uid" component={Userpage} />
<Footer />
</div>
</Router>
The app is hosted using Firebase hosting.
If I open my website and click around such that the router takes me to /map/uid, it loads fine. But if I close the browser and then try to explicitly navigate to <domain>/map/<known uid>
, I get a "no page found" page from Firebase. This is my first time using react-router.
Update #1
I have updated my firebase.json
to:
{
"hosting": {
"public": "build",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
]
}
}
I no longer receive the "Page not found" page; however, the content of my react app never loads, and I notice in my console an error:
Uncaught SyntaxError: Unexpected token <
Update #2
I now understand why I am getting the error. Looking at the Sources tab in Chrome dev tools, my static/ folder has a strange name (static/css
rather than static
) only when I directly navigate to /map/{known uid}
. When I navigate to the home page, all loads fine.
This explains the error. I am still not sure how to fix.