-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
Unability to link to an internal non-SPA link #3309
Comments
I'd strongly vote for the idea that So, from my understanding the problem is only in terms of navigating to such (valid) link as a SPA-route or not. And this, IMHO, is smth that can be handled transparently to the user. Also, from UX and marketing POV, "the less Docusaurus-specific modifications one needs to do when migrating from static generators, the better and more appealing that seems: 😎 |
I agree that we should try to provide good defaults, and not modify the docs for this.
As explained there: #3303 (comment)
Jekyll is not a SPA, it does not have to choose between Also, if you have a jekyll doc at I'm pretty sure I've already seen both of these use cases already (one of the 2 is yours). How can we solve this without being biased in favor of one particular use-case, preventing the other to work? Apart from additional config or some markdown tricks to pass additional info, I don't see. How did Jekyll do on your |
@coliff just seen this SO answer from @yangshun https://stackoverflow.com/a/55940426/82609 I suggest you try to add https://github.com/vitaliy-bobrov/remarkable-extlink with target=_blank, and Docusaurus will not try to navigate to it as a SPA link Edit: oh nevermind it's code for v1 |
I'll move that discussion here, to keep it under the dedicated issue 🙂
From your answer in #3278 (comment):
I got an impression that, by default, "root" links are prepended with This seems like a reasonable default behaviour to me.
Yep, that's why I refer to them as static generators. But that was not my point. Again, I'm talking from the user perspective here, and talking about default SPA-navigation behaviour, I see it reasonable to keep the same defaults for non-SPA. Also, I can imagine that picking the right defaults to hit the majority of users is hard. Maybe it's worth to make this default behaviour configurable, if there is a real concern? But that may sound as an unnecessary complication 🙂
There was no internal deployment before. To introduce one, we are migrating our website to Docusaurus, that's one of the reasons. |
Actually checked it and I think The general idea is that we try to ensure that a site that works without a baseurl should keep working if we add a baseurl, so yes it probably makes sense to support your usecase by default (linking to Will try to find a good way to support these usecases, because with i18n it's very likely that we'll use baseUrl = |
👀
@slorber thanks a lot! |
I'll try to make this possible soon, as I think there is currently no workaround to solve your problem. Need to figure out which solution/api first, have some ideas but not sure which is best. It's not possible to apply baseurl in markdown absolute links so that it works fine on your 2 distinct envs. |
So, I made this PR to make the It's not an ideal solution as it requires updating markdown but it should work with or without baseurl, as seen on this page: https://deploy-preview-3347--docusaurus-2.netlify.app/classic/markdown-tests/ Other ideas I have are more complex to implement, and I'm not even sure to get the API right, so I prefer to take more time to figure this out. |
@slorber not sure I got it right. I thought you decided to make The testing section seems incorrect. I suppose these 2 urls should not point to the same destination: |
Both will be prefixed by baseUrl (if any) so that links are not sensitive to baseUrl. It's not a final solution, but if we find a better one, there should be a simple migration path (like just removing the |
@slorber sorry! I updated the comment in between, after actually checking the Testing Page. I see your point, I guess quicker solution is better for now (sad, that we need to have this special case when writing docs :)) While testing I guess I found at least one strange thing:
|
Yes, I'll figure out how to make this configurable from the outside later. Yes you are wrong both should resolve to the same path, one is a relative path, the other is absolute but it's the same path in the end |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
it would be great to add the |
Summary: Links to pages in static resources have been broken for a while it seems: Docusaurus generates a Page not Found error for them, then refreshing the URL loads the page properly... This is because of wrong routing from the Docusaurus Single-Page App. See facebook/docusaurus#3309 A suggested workaround is to prepend `pathname://` in front of each link not managed by docusaurus. This makes the page open in a new tab, which is actually quite ok for our use cases: OCaml API docs and man pages. Reviewed By: skcho Differential Revision: D26544273 fbshipit-source-id: 2ed86ca4f
Would be really great to be able to force the link to be internal and also use the |
In the meantime a workaround is setting |
So you mean using Afaik React-Router always handles |
…rnal (workaround from facebook/docusaurus#3309) Release-As: 5.1.4
Another downside of current solution is that when used in the footer, it appends the "external link" icon, even though the link is on the same domain and may be just the parent directory from where we currently are. Were there any new ideas proposed to handle this? Maybe some RFC that I couldn't find through search? |
For anyone looking for a quick workaround, you can "swizzle" NotFound page and insert code there to detect this condition. Run Here is a sample implementation that would reload the page in hopes of getting the correct content and if it detects that current page was recently loaded due to a reload it would show the default 404 page. export default function NotFoundWrapper(props: Props): JSX.Element {
const { type, loadEventEnd } = window.performance.getEntriesByType(
'navigation',
)[0] as PerformanceNavigationTiming
const isPageReload = type === 'reload'
const isRecentLoad = window.performance.now() - loadEventEnd < 2500
const isReload = isPageReload && isRecentLoad
if (!isReload) {
location.reload()
return (
<>
<span></span>
</>
)
}
return (
<>
<NotFound {...props} />
</>
)
} |
🐛 Bug Report
Related to #3303 (comment)
Imagine you have
/static/javadoc/index.html
You should be able to link to this page that is not managed by Docusaurus, using:
or
Yet, the link uses
history.push()
as it thinks it's an SPA internal link, and we end up with the 404 as no SPA route is found.It works after a refresh though, or if we use an URL with the http/https protocol.
Not sure how to solve this problem,
Maybe we should read the routes file directly on link, and when we press, only use
history.push()
if the link is a known internal SPA link, else fallback to a regular non-SPA navigation?I don't think there is a std way to provide additional link infos in Markdown, nor if MDX supports that. Another option would be to use a special protocol so that we force the link to consider it as a non-SPA link:
Another solution would be to provide a remark plugin so that user can tell which URLs are to be considered as external. It may be overwhelming for a site user to write a remark plugin, so we could just ship a default one in MDX loader, that would read a list of paths to consider external in site config? Inspiration => https://github.com/remarkjs/remark-external-links
The text was updated successfully, but these errors were encountered: