react-router icon indicating copy to clipboard operation
react-router copied to clipboard

[Feature]: createHref support.

Open hellohejinyu opened this issue 4 years ago • 1 comments

What is the new or updated feature that you are suggesting?

createHref need back.In some scenarios, you need to dynamically calculate the url and then use it.

Why should this feature be included?

In the previous v5 version, I can get the href in the following code.

import { useHistory } from 'react-router-dom'

const Cpt = () => {
  const history = useHistory()

  return <button 
    onClick={() => {
      const href = history.createHref('/bar')
      window.open(`http://some-other-domain.com${href}`)
    }}
  >
    button
  </button>
}

But in the latest version, I can't achieve my needs.I just found the resolvePath method.But its result is inconsistent with createHref. And useHref cannot dynamically pass in parameters.

image

So, I think createHref is still necessary for its existence, or I missed something, there is a better way to achieve it in the v6 version.

hellohejinyu avatar Nov 09 '21 09:11 hellohejinyu

Related to #8278

timdorr avatar Nov 09 '21 19:11 timdorr

I'm going to convert this to a discussion so it can go through our new Open Development process. Please upvote the new Proposal if you'd like to see this considered!

brophdawg11 avatar Jan 09 '23 20:01 brophdawg11