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 to "/" with basename adds extra trailing slash

See original GitHub issue

Version

4.2.0

Test Case

https://codesandbox.io/s/6llwm7m8zz

Steps to reproduce

<BrowserRouter basename="/foo/bar">
    <Route path="/" component={App}/>
</BrowserRouter>
<Link to="/" />

Expected vs. Actual Behavior

the link takes me to http://host/foo/bar/ (with trailing slash) when I expect http://host/foo/bar (without trailing slash)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
ajenkins-kyrcommented, Aug 17, 2018

Is there any way to get the behavior that @mmartha is looking for using basename without implementing some kind of redirect behavior? This seems like a very normal use case and I can’t figure out a working solution other than not using basename altogether.

2reactions
mmarthacommented, Jun 26, 2018

thanks @timdorr, I’ve implemented a server side redirect as a workaround, looks like I’ll just stick with that!

Do you have any explanation or link to a discussion thread for why this was decided to be the expected behavior? It doesn’t seem ideal since the root route is a file rather than a directory. Additionally, it seems strange that the root route’s behavior (wrt trailing slash) would differ when using basename vs. when not.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Link to "/" with basename adds extra trailing slash · Issue #6226
The new logic should be such that if either basename or the <Link to> have a trailing slash, the resulting URL should have...
Read more >
Why is react-router appending a trailing slash in the address ...
Example: going to http://localhost:8080/some-route will get changed to http://localhost:8080/some-route/ .
Read more >
React Router - Remove Trailing Slash from URLs
This is a super quick example of how to remove trailing slashes from URLs in React apps that use React Router.
Read more >
Trailing slashes on symbolic links to directories
I'm trying to emulate the process of path resolution (see man page path_resolution) in unix-like systems. My OS is Linux with GNU coreutils...
Read more >
Should You Have a Trailing Slash at the End of URLs? - Ahrefs
A trailing slash is a forward slash (“/”) placed at the end of a URL such as domain.com/ or domain.com/page/. But should you...
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