Ok, so I\'ve made a SPA using React and React-Router and have pushed it to github pages, but none of the routes I have written work when I refresh or click back in my browse
If you are using create-react-app (I haven't tested this in any other environment) you can use browserRouter
, you will need to pass a basename
prop to the component with this env variable: process.env.PUBLIC_URL
.
Your router should now look like this:
{/* routes */}
For more info you can checkout this Github thread
Use process.env.PUBLIC_URL in your route definitions so that they work both in development and after deployment. For example: . This will be empty in development and ... (inferred from homepage) in production.