pathPrefix not working after building and serving Gatsby site
See original GitHub issueDescription
Problem when using pathPrefix
option in gatsby-config
when serving the build.
The goal is to have a gatsby app, that builds, and the build is then served from an (express) app. You would have the main express app serving a static page, called page-2
(the gatsby page) at www.myapp.com/banana/page-2
.
Due to banana
there is a pathPrefix
of “/banana” added to the config. The build then uses gatsby build --prefix-paths
to utilize this.
Steps to reproduce
Demo Repo: https://github.com/jfarris587/gatsby-demo
A):
- Clone the repo
- run
yarn build
and thenyarn serve
- Go to
localhost:9000
- Attempt to navigate
- Attempt to go to
localhost:9000/page-2
- Try and click the text to trigger alert
B):
- Change build script to normal
yarn gatsby build
- Remove pathPrefix from gatsby-config file
- Repeat steps above
Expected result
I should be able to go to the home page, navigate to the other page and click the text to see the javascript working.
Actual result
Trying (A): You will notice that going to the home page works, but clicking the link takes you to unknown page. However, if you go to /page-2
directory with no “banana” prefix, then it takes you to the page… But the javascript doesn’t work. When clicking the h3
an onClick fires to alert you…
Trying (B): You will get the expected behavior, but it doesn’t utilize a prefix, which is needed for serving page-2
from an express app
Notice that yarn Dev in Chrome does work. (IE seems to have seperate polyfill issue in development mode). However, serving the build gives above problems
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (2 by maintainers)
If anyone coming here like me …after building your application with
--prefix-paths
serve your site also with--prefix-paths
! Modify your scripts in package.json as"serve": "gatsby serve --prefix-paths -o",
Thanks man! Solved my problem. It’s not specified in the docs