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]: NavLink and Link cannot parse the href attribute of <a> tag correctly when use createHashRouter method to create hash router. #9578

Closed
masonsi-dev opened this issue Nov 10, 2022 · 1 comment
Labels

Comments

@masonsi-dev
Copy link

What version of React Router are you using?

v6.4.2

Steps to Reproduce

const router = createHashRouter(
  createRoutesFromElements(
    <Route>
      <Route path="/" element={<Home />}  />
      <Route path={"pageA"} element={<PageA />} />
      <Route path={"pageB"} element={<PageB />} />
    </Route>
  )
)

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
  <React.StrictMode>
    <RouterProvider router={router} />
  </React.StrictMode>
)

const Home = () => {
  return (
    <>
      <ul>
        <li>
          <NavLink to={'pageA'}>PageA</NavLink>;
        </li>
        <li>
          <Link to={'pageB'}>PageB</Link>;
        </li>
      </ul>
    </>
  )
}

CleanShot 2022-11-10 at 12 02 30

Expected Behavior

The tag's href attribute should be a hash url. It would work if I use instead of createHashRouter.
I change the code to . All the rest keeps same.

ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
  <HashRouter>
    <Routes>
      <Route path="/" element={<Home />}  />
      <Route path={"pageA"} element={<PageA />} />
      <Route path={"pageB"} element={<PageB />} />
    </Routes>
  </HashRouter>
);

CleanShot 2022-11-10 at 12 06 52

Actual Behavior

CleanShot 2022-11-10 at 12 02 30

@masonsi-dev masonsi-dev changed the title [Bug]: NavLink and Link cannot parse the attribute of <a> tag correctly when use createHashRouter method to create hash router. [Bug]: NavLink and Link cannot parse the href attribute of <a> tag correctly when use createHashRouter method to create hash router. Nov 10, 2022
@brophdawg11
Copy link
Contributor

I think this should be fixed in 6.4.3 via #9409

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