-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redirects to static content don't redirect #3421
Comments
Hi What you are looking for is the "version alias" feature, that I plan to implement as part of this RFC, probably in October: #3285 We also have a redirect plugin BTW, maybe it will work better for your use case, as it will be able to redirect URLs like I think your solution looks fin, and wonder if it does not work because of the trailing slash. Maybe you should try to remove the trailing slash and see if it works better?
I don't know what is happening, but Redirect is the raw redirect from ReactRouter, it does not do anything special so this is weird. |
Ohhh but wait, this page is not managed at all by docusaurus right? https://sap.github.io/cloud-sdk/api/1.28.1/ Docusaurus/React won't even be able to render such an external page, that's why it shows Docusaurus 404 You can't Redirect to external pages with the Redirect component, this is for redirecting client-side with SPA-like navigation (based on Also worth mentioning that if you can afford it, you'd rather perform redirects at the server level (http status 302 etc). Unfortunately it is not possible with Github but it is easy on other hosts like Netlify or Vercel that I'd recommend you to adopt, as they are very easy to setup and will give you a much better experience (including deploy previews in each doc modification PR) |
Hey @slorber, thank you for your response. I tried various combinations of the urls - with slashes, without and also linking to the index.html directly. I think you are right, this is not managed by docusaurus, because we had a similar issue before, when we tried linking to the api docs from a different page. This resulted in a broken link error, which we were only able to solve by using the absolute link. I think I got some inspiration from your comments on how to solve this symptom, but I would actually like to have these pages managed by docusaurus as well. Is there a recommended way on how to include generated api documentation? We currently add it as static content. |
Hey @marikaner, I understand that it might be useful that Docusaurus is aware of this I was able to do something like this, but it's a bit hacky:
The problem is that you first have to navigate to an empty doc page before being redirected so the user feedback feels a bit weird. But your problem is actually that you want to navigate to a path of the subdomain, but that Docusaurus don't know about. Unfortunately, we don't have yet a good API surface to solve this problem, but this is related to other issues:
So, technically, you should be able to link to your version using something like My suggestion for your usecase would be:
I don't think the latest page should be managed as a docusaurus document, as it involves the tradeoff of loading React, hydrating, displaying an empty doc even before being to navigate, so this gives a weird UX. |
Hey @slorber, I was able to use the workaround for links unknown to docusaurus, when linking directly. In the second step I tried to follow your suggestion and redirect using the redirect plugin (server redirects are unrealistic right now).
This is my configuration: plugins: [
[
'@docusaurus/plugin-client-redirects', {
redirects: [
{
from: '/api/latest',
to: `/api/${latestJsRelease}/`
}
]
}
]
] I cannot use the pathname workaround here as it gives me this error:
|
Oh you are right, the redirect plugin is made to redirect to existing docusaurus pages. And when I said to use The solution could be to add this redirect in <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<script>
window.location.href = 'api/1.28.1';
</script>
</html> If you need it to be dynamic, you should generate this file as a build step and put it in the generated As long as at the end of the build, you have an HTML file that redirects (in |
Closing as it seems to be rather a question... |
🐛 Bug Report
In our docs, we have API docs listed by version. I wanted to add a link that always points to the latest version of the API docs, aka:
api/latest/
should redirect toapi/1.28.1/
e. g.The url is correctly replaced, but the redirect does not happen and I am left with a "Page not found" error. The status code is 200, while I would expect a 301. When reloading the page I am actually presented with the correct document.
Have you read the Contributing Guidelines on issues?
Yes.
To Reproduce
Expected behavior
Redirects to the linked page and status code 301.
Actual Behavior
Replaces link correctly, but has status code 200 and content is "Page not found".
Your Environment
Reproducible Demo
Speaking in docs sources
This is the file that is supposed to induce the redirection:
https://github.com/SAP/cloud-sdk/blob/documentation/src/pages/api/latest.mdx
to e. g. this file https://github.com/SAP/cloud-sdk/blob/documentation/static/api/1.28.1/index.html
Speaking in links
https://sap.github.io/cloud-sdk/api/latest/ should redirect to https://sap.github.io/cloud-sdk/api/1.28.1/
The text was updated successfully, but these errors were encountered: