Link Component with or without useBaseUrl
See original GitHub issueđ Bug Report
When using the useBaseUrl hook, the base url is composed dependent on if current page was navigated to through âspa navigationâ or visiting the url directly. If one navigates to a url with the âspaâ mode, the trailing slash appears to be missing. If you refresh the page, the trailing slash is added. The trailing slash appears to break all of the relative links then.
This could possibly be a misunderstanding with the docs and we are not supposed to be using the hook, but the docs for Link
and useBaseUrl
do not make it clear when you should use useBaseUrl
.
Have you read the Contributing Guidelines on issues?
Yes.
To Reproduce
(gif alt: shows steps as noted above)
Expected behavior
Internal routing to work.
Actual Behavior
It seems to work inconsistently depending on how you have arrived on the page.
Your Environment
- Docusaurus version used: 2.0.0-alpha.55
Reproducible Demo
- Permalink to live url: https://deploy-preview-49--tauri.netlify.app/
- Permalink to code at above url: https://github.com/tauri-apps/tauri-docs/tree/ba99d196f5022807922b3efd0b4330c6e37e4c46
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Docusaurus Client API
The component is a wrapper around react-router's <Link> component that adds useful ... import useBaseUrl from '@docusaurus/useBaseUrl';
Read more >Can I set a base route in react-router - Stack Overflow
The base URL for all locations. If your app is served from a sub-directory on your server, you'll want to set this to...
Read more ><Link> ¡ React Router
The className a <Link> receives when its route is active. No active class by default. activeStyle. The styles to apply to the link...
Read more >Docusaurus Client API
The component is a wrapper around react-router's <Link> component that adds useful enhancements ... import {useBaseUrlUtils} from '@docusaurus/useBaseUrl';
Read more >how to use base url in react Code Example
Answers related to âhow to use base url in reactâ ... how to get url in react ¡ get current url react router...
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
I think Docusaurus should take a stance on this and introduce trailing slashes to all Docusaurus-generated links while weâre still in alpha. Some users Markdown links might break now but at least itâs consistently breaking in both development and production, unlike now when itâs breaking only in production and sometimes depending on hosting provider.
As a user, always using a trailing slash doesnât currently seem to be an option. The
navbarsidebar sends you to pages without trailing slashes. Then refreshing that page adds a trailing slash.As far as I can tell, this means all relative URLs are broken depending on how you use the website. IMO we should issue a fix for this soon or make it clearer that they donât work, maybe by throwing an error at build time or something like that.
The docs are still implying relative URLs should be ok: https://v2.docusaurus.io/docs/markdown-features#referencing-other-documents
Also, even when specifying a relative url in a markdown file, the resultant a-tag on the page has an absolute href, so I donât think the browserâs behaviour is the problem here, the wrong absolute path seems to be being produced by docusaurus itself.