Skip to content
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

[Bug]: Link (and NavLink) strip hash when using createBrowserRouter and RouteProvider #9484

Closed
rehos opened this issue Oct 21, 2022 · 2 comments
Labels

Comments

@rehos
Copy link

rehos commented Oct 21, 2022

What version of React Router are you using?

6.4.2

Steps to Reproduce

Context: Landingpage on which a user can navigate to different sections by using anchor tags.

See Stackblitz for reproduction of the issue. [UPDATE] createMemoryRouter has the same issue as createBrowserRouter.

I have been able to track this issue down to createHref in router.ts

function createHref(location: Partial<Path> | Location | URL) {
  return (location.pathname || "") + (location.search || "");
}

Expected Behavior

If I specify a Link or NavLink I expect the anchor tag to preserve the hash

Given:

<Link to="/#about">About</Link>

I expect:

<a href="/#about">About</a>

Same for NavLink

Actual Behavior

If I specify a Link or NavLink the anchor tag doesn't preserve the hash

Given:

<Link to="/#about">About</Link>

I actually get:

<a href="/">About</a>

Same for NavLink

@rehos rehos added the bug label Oct 21, 2022
@brophdawg11
Copy link
Contributor

Thanks for the reproduction! I think this is the same underlying issue as #9392 and it looks like 6.4.3-pre.0 does fix the issue in the stackblitz. Please re-open the issue if you're still seeing problems on the prerelease! We hope to have a 6.4.3 stable out soon.

@rehos
Copy link
Author

rehos commented Oct 25, 2022

Thank you, I tested our customer's site with 6.4.3-pre.0 and can confirm it is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants