Skip to content

[Feature]: createHref support. #8292

@hellohejinyu

Description

@hellohejinyu

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature-requestUsed to close PRs that haven't gone through/been accepted the Proposal process yet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions