reactjs / react-router-redux

Ruthlessly simple bindings to keep react-router and redux in sync
https://www.npmjs.com/package/react-router-redux
MIT License
7.81k stars 644 forks source link

Redirect not preserving params #596

Closed amaschas closed 7 years ago

amaschas commented 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.

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;
timdorr commented 7 years ago

You have the wrong repo.

amaschas commented 7 years ago

Oops, thanks, will refile over there.