"You are trying to create client-side redirections to paths that do not exist" to folders without trailing slash
See original GitHub issueHave you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Prerequisites
- I’m using the latest version of Docusaurus.
- I have tried the
npm run clear
oryarn clear
command. - I have tried
rm -rf node_modules yarn.lock package-lock.json
and re-installing packages. - I have tried creating a repro with https://new.docusaurus.io.
- I have read the console error message carefully (if applicable).
Description
For paths to folders without a trailing slash, hosts will typically 302 redirect to the path with the slash
e.g. https://docs.sheetjs.com/docs/getting-started redirects to https://docs.sheetjs.com/docs/getting-started/
@docusaurus/plugin-client-redirects
does not seem to be aware of this behavior for folders that have subfolders.
This redirect works
{ from: '/docs/installation', to: '/docs/getting-started/' }, // works
This redirect elicits the error mentioned in the title:
{ from: '/docs/installation', to: '/docs/getting-started' }, // elicits error
The fact that it works for leaf folders that only have index.html
suggests this is a bug in the redirect scanner:
{ from: '/docs/example', to: '/docs/getting-started/example' }, // this works, even though `example` is a folder
Reproducible demo
https://github.com/SheetJS/docs.sheetjs.com
Steps to reproduce
git clone --depth=1 https://github.com/SheetJS/docs.sheetjs.com
cd docs.sheetjs.com/docz
npm i
npm run build ## note: this should work
sed -I '' "s#started/'#started'#g" docusaurus.config.js
npm run build ## this will fail with the aforementioned error
If the sed
command fails, the edit is in docusaurus.config.js
:
redirects: [
{ from: '/docs/example', to: '/docs/getting-started/example' },
- { from: '/docs/installation', to: '/docs/getting-started/' },
+ { from: '/docs/installation', to: '/docs/getting-started' },
]
}]
Expected behavior
It should create the redirect
Actual behavior
[ERROR] Error: You are trying to create client-side redirections to paths that do not exist:
The path in question is not listed in the valid paths
Your environment
No response
Self-service
- I’d be willing to fix this bug myself.
Issue Analytics
- State:
- Created a year ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Integrated handling of trailing slashes in Gatsby #34205
A nuance here is that we don't explicitly call out the presence of automatic redirects when using the trailingSlash setting.
Read more >Bug in non-trailing slash rewrite
The first and recommended solution is make that redirect rule a “rewrite” rule be changing the HTTP status code used from 200 to...
Read more >How can I configure IIS to serve directories without trailing ...
Now all requests with a trailing slash get it removed, IIS no longer performs 301 redirects to add back the slash, the client...
Read more >Gatsby: to slash or not to slash?
Here comes the reason you should use trailing slashes on Gatsby: the path string passed to createPage() becomes a directory, and the resulting ......
Read more >Trailing Slash - next.config.js
You can configure this behavior to act the opposite way, where urls without trailing slashes are redirected to their counterparts with trailing slashes....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In a structure like:
When
trailingSlash
is undefined, theroutesPaths
key exposed to in the postBuild props is:Those paths are used in the validation.
One way to resolve the issue without disrupting other plugins is to add both slash variants to the validation.
https://github.com/facebook/docusaurus/blob/4b5a47ba37ffdfbcf46e23790ff0cfe6c4745e14/packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts#L81
Happy to review your PR
We recommend an explicit trailing slash, but only for Github Pages users, not all users.
I wouldn’t recommend GitHub pages in the first place, Vercel/Netlify are much better alternatives and you don’t always need to use the trailingSlash setting with those.