-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
<Redirect /> can't convert additional parameters. #4919
Comments
A The approach that I would take would be to use a <Route path="/profile/:userId" render={({ match }) => (
<Redirect to={`/about/${match.params.userId}`} />
)} /> |
@pshrmn |
I'm not personally a fan of the idea because I don't like overloading the |
Couldn't |
@jacobrask See #5368 |
I'd also like to be able to pass a |
Do I understand correctly that with the merging of #5368 we can go |
I used @pshrmn suggestion in #4919 (comment) and created a Redirect component of my own. Now, instead of using React Router's Redirect, I use this: // Redirect.js
import React from 'react'
import {
Redirect as ReactRouterRedirect,
Route,
} from 'react-router-dom'
export default function Redirect (props) {
const {
from,
to,
...rest
} = props
if (!from) {
return <ReactRouterRedirect {...props} />
}
return (
<Route
path={from}
render={({ match }) => {
const paramKeys = Object.keys(match.params)
const toWithReplacedParamsKeys = paramKeys.reduce((url, key) => (
url.replace(`:${key}`, match.params[key])
), to)
return <ReactRouterRedirect to={toWithReplacedParamsKeys} {...rest} />
}}
/>
)
} Hope it helps. |
@mjackson or @ryanflorence What do you think of #4919 (comment)? Is it worthy of a behavior that |
It's worth mentioning this runs contrary to the documentation: |
That's in 4.3.0-rc.2 |
Hi,
In
react-router v3
, we can use<Redirect />
like this:It will be covert correct:
Unfortunately, it's not work in
react-router v4
. It will be get:Is there a new way to do this in v4?
version: react-router-dom 4.0.0
The text was updated successfully, but these errors were encountered: