I'm building a website with Gatsby and Strapi. I'm using dynamic routes.
With gatsby develop, everything fine.
With gatsby build, links between pages are working, but typing the URLs give me 404.
Example: I can go from / to /room with a click but when I type /room, I get a 404.
How should I fix this? Am I missing something?
index.js routing part:
<Router basepath="/">
<Doors path="/" exitTransition={exitTransition}></Doors>
<Room path="/room" exitTransition={exitTransition}></Room>
<Sound path="/sound" sounds={sounds} currentSoundIndex={currentSoundIndex} setCurrentSoundIndex={setCurrentSoundIndex} audioPlayerRef={audioPlayerRef}></Sound>
<Cloakroom path="/cloakroom" clothes={clothes}></Cloakroom>
{clothesRoutes}
</Router>
gatsby-node.js
exports.onCreatePage = ({ page, actions }) => {
const { createPage } = actions
if (page.path === `/`) {
page.matchPath = `/*`
createPage(page)
}
}
Note: Local http-server build is working. But on my client's hosted server it's not. I'm using Router from @reach/router.
Thank you so much for your help!
I got it resolved.
I simply needed to place an
.htaccessfile in the public directory with that content: