wouter icon indicating copy to clipboard operation
wouter copied to clipboard

v3.0.0-rc.1: When use hash router, Ctrl+click on <Link>, new window is opened with wrong url

Open fuchen opened this issue 1 year ago • 2 comments

3.0.0-rc.1

<Router hook={useHashLocation}>
  <Link to="/abc">link text</Link>
</Router>

Click the link, windows location is changed to https://example.com/#/abc as expected. Ctrl+click, a new tab is opened at https://example.com/abc#/abc

fuchen avatar Nov 30 '23 16:11 fuchen

Yeah, that is a long known problem that we don't have a solution for yet. This might be a duplicate of https://github.com/molefrog/wouter/issues/215, could you take a look?

molefrog avatar Dec 01 '23 08:12 molefrog

I use following code to work around:

const HashLink = ({ to, children }: { to: string, children: React.ReactNode }) => {
  return (
    <a href={'#' + to}>
      {children}
    </a>
  )
}

Seems that the problem is we cannot get the composed URL with current useLocation API.

fuchen avatar Dec 01 '23 12:12 fuchen

Hello everyone, the support for this has finally landed in 3.1.0. Thank you for participating in this discussion. https://github.com/molefrog/wouter/releases/tag/v3.1.0

molefrog avatar Mar 11 '24 10:03 molefrog