Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Client Side Routing in Gatsby

Is it possible to disable client side routing in Gatsby?

I'm using Gatsby to generate a static site which only has one page and will be served from AWS/S3. I'm running into an issue caused by Gatsby removing the object suffix from the URL (https://s3.amazonaws.com/top-bucket/sub-bucket/index.html becomes https://s3.amazonaws.com/top-bucket/sub-bucket/) after the page and the Gatsby runtime loads. This issue does not happen if I disable JavaScript, so I'm pretty certain it's caused by Gatsby's use of React/Reach Router.

Is there any way to disable this behavior? I know I can probably setup a redirect on S3 to handle the request to the bucket, but I'd prefer to do this at the application level, if possible.

like image 384
pdoherty926 Avatar asked Jan 04 '19 20:01

pdoherty926


1 Answers

This is a hack and may not work in anyone else's application or break with future releases of Gatsby, but I was able to prevent this redirect by setting window.page.path = window.location.pathname; in gatsby-browser.js. This short circuits a conditional check in production-app.js, which attempts to "make the canonical path match the actual path" and results in the (IMO) unexpected behavior referenced above.

like image 194
pdoherty926 Avatar answered Sep 18 '22 20:09

pdoherty926