Add push prop to NamedRedirect to pass on to Redirect

This commit is contained in:
Kimmo Puputti 2017-02-16 17:16:12 +02:00
parent 4045146364
commit 78cfe3d75f

View file

@ -8,20 +8,20 @@ import { pathByRouteName, withFlattenedRoutes } from '../../util/routes';
import * as propTypes from '../../util/propTypes';
const NamedRedirect = props => {
const { name, search, state, params, flattenedRoutes, ...rest } = props;
const { name, search, state, params, flattenedRoutes, push } = props;
const pathname = pathByRouteName(name, flattenedRoutes, params);
const locationDescriptor = { pathname, search, state };
return <Redirect to={locationDescriptor} {...rest} />;
return <Redirect to={{ pathname, search, state }} push={push} />;
};
const { arrayOf, object, string } = PropTypes;
const { arrayOf, object, string, bool } = PropTypes;
NamedRedirect.defaultProps = { search: '', state: {}, params: {} };
NamedRedirect.defaultProps = { search: '', state: {}, push: false, params: {} };
NamedRedirect.propTypes = {
name: string.isRequired,
search: string,
state: object,
push: bool,
params: object,
flattenedRoutes: arrayOf(propTypes.route).isRequired,
};