question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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) wWo2L2Mu83

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
yangshuncommented, Jun 5, 2020

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.

3reactions
jknoxvillecommented, Jun 1, 2020

So either you use a trailing slash for all your internal links, or use absolute links.

As a user, always using a trailing slash doesn’t currently seem to be an option. The navbar sidebar 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found