Closed amaschas closed 7 years ago
When I attempt to use redirect like this:
<Switch> <Route path="/foo/:id/landing" component={FooComponent} /> <Redirect from="/foo/:id" to="/foo/:id/landing" /> </Switch>
Visiting foo/2 redirects me to foo/:id/landing. The preferred behavior would be to interpolate the param and redirect to foo/2/landing.
foo/2
foo/:id/landing
foo/2/landing
I'm using a workaround from this thread for now, but this should probably be the default behavior.
import pathToRegexp from 'path-to-regexp'; import { Route, Switch, Redirect } from 'react-router-dom'; const RedirectWithParams = ({ exact, from, push, to }) => { const pathTo = pathToRegexp.compile(to); return ( <Route exact={exact} path={from} component={({ match: { params } }) => ( <Redirect to={pathTo(params)} push={push} /> )} /> ); }; export default RedirectWithParams;
You have the wrong repo.
Oops, thanks, will refile over there.
When I attempt to use redirect like this:
Visiting
foo/2
redirects me tofoo/:id/landing
. The preferred behavior would be to interpolate the param and redirect tofoo/2/landing
.I'm using a workaround from this thread for now, but this should probably be the default behavior.