Dynamic URLs don't use `basePath` correctly
See original GitHub issueAre you reporting a bug?
Yes
The basePath
(and stagingBasePath
and devBasePath
) works fine for the static URLs that are generated in .html files, but URLs that are dynamically created via JavaScript don’t use basePath
correctly. Sometimes they leave it off altogether. Other times they repeat it twice.
Related (but different) issues:
Environment
react-static -V
: 6.2.0node -v
: 10.11.0npm -v
: 6.4.1- Operating system: Windows 10
- Browser and version (if relevant): Chrome 71
Steps to Reproduce the problem
-
Create a new project using the “basic” template
-
Add the following to the
static.config.json
basePath: "PRODUCTION",
stagingBasePath: "STAGING",
devBasePath: "DEV",
- Run the dev server (
npm start
) and see that everything works correctly
- (although it’s served from
/
not/DEV
see Issue #972)
-
Do a staging build (
npm run stage
) -
Move the contents of the
dist
folder todist/STAGING
to match our site config
mv dist STAGING
mkdir dist
mv STAGING dist/STAGING
-
Remove the
-s
option from theserve
script inpackage.json
. That option causes problems due to the 404 issue that I’m demonstrating here. -
Run the static server (
npm run serve
)
- The site is served from
/STAGING
and not from/
. This is good because it accurately tests whether our site will work correctly in a non-root directory. 👍
- Open your browser dev tools and look at the “Network” tab.
-
Try to browse to a few different pages of the site. You’ll see a lot of 404 errors.
-
All the URLs in the .html files are correctly prefixed with
/STAGING
and work correctly -
URLs that are loaded dynamically via JavaScript are mostly broken.
-
Some are missing the base path (e.g.
/templates/src-pages-404.xxxxx.js
) -
Some have the base path twice (e.g.
/STAGING/STAGING/about/routeinfo.json
)
-
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (6 by maintainers)
@tannerlinsley, Please reopen when you get the chance, thanks!
We’re also experiencing this issue and seemingly-related
basePath
bugs with both React-Static 5.9.12 and 6.x. I’m a huge fan of React-Static, I’ve migrated projects from other SSR libraries and it’s been a great experience overall, but unfortunately this is a showstopping blocker. I really appreciate all the work you’ve done though, using React-Static has been like a breath of fresh air!I’d like to help out as well and I’ll take the information above as a jumping off point for my own attempts to root cause this cluster of issues. In terms of branch(es) to work against, is
master
the preferred branch or could it also be worthwhile to look atv5
andv7
?Master is up to date for v6 so use that one! Thanks for your willingness to help!
On Thu, Feb 28, 2019 at 3:32 PM Duncan notifications@github.com wrote: