Link to "/" with basename adds extra trailing slash
See original GitHub issueVersion
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:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top 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 >
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 Free
Top 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

Is there any way to get the behavior that @mmartha is looking for using
basenamewithout 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 usingbasenamealtogether.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.