Disable Clientside Routing

Viewed 301

I have a static page that is rendered (with additional data) by a Go Application based on the requested path. This works fine, however React fails to load because Gatsby cannot find the page-data.json based on the given path.

I already tried disabling clientside routing with the '@wardpeet/gatsby-plugin-static-site' plugin, however the problem still exists.

I use the default gatsby template with a modified html.js and without any or tags.

I would like to disable clientside routing completely (and remove the app-data.json/page-data.json files) or at least route any request to the same file, so I can deploy the site regardless of the domain path.

Thanks in advance

1 Answers

I'm not sure I properly understand your case, but I gather the following points:

  • Once running in the browser, Gatsby can't find your app-data.json and page-data.json files;
  • Your Gatsby site appears to be served from a non-root path (for example www.example.com/some/more/path/(gatsby site)).

If that is all there is to it, then what you want is simply to set a "Path Prefix" when your gatsby site is built. In short, what you need to do is:

  1. In your site's gatsby-config.js, export a property named 'pathPrefix' specifying the path from which your site will be served. For example:
module.exports = {
  pathPrefix: `/blog`,
}
  1. When you build your site, pass the flag --prefix-paths to the gatsby command. For example:
gatsby build --prefix-paths

Both steps are required, otherwise, you won't see any difference. Once you will have done this, the client side Gatsby application should be able to correctly fetch all required files.

You do not need to disable client side routing. Client side routing is almost always a good thing, since it makes navigation between pages significantly faster. You should remove that plugin.

Related