The Why
While the client-side router knows about this path, there is no corresponding HTML file. When the browser looks at the site it first loads the 404.html
file generated by gatsby, which includes the client-side router. Once the router completes its initialization it reads the path and loads the correct page. Meaning you end up at the right place but there's half a second of landing on the wrong page.
How to fix It
The general solution is to tell your server to redirect the /sample/
path to your /sample/index.html
file. The way to do this depends on your host, but I'll provide the name of the technique for various hosts in case you want to look it up. It's usually called URL Rewriting and should be supported by every major hosting platform.
Heroku
The Heroku section of the gatsby deploy documentation suggests using the heroku-buildpack-static module which has built-in support for "custom routes" which will solve this for your case using syntax like this:
{
"routes": {
"/sample/**": "sample/index.html",
}
}
AWS Amplify
You need to add the redirect in the AWS Amplify console. For this example, the params are:
- Source URI:
/sample/<*>
- Target URI:
/sample/index.html
- Type: 200
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…