Improve routing

- Allow setting `preferLogin` in route config to enable redirecting
   to login page instead of signup page
 - Add missing search params to the auth redirect
This commit is contained in:
Kimmo Puputti 2017-08-15 16:03:24 +03:00
parent 54e42b7ad8
commit 8d9c078309

View file

@ -54,18 +54,22 @@ class RouteComponentRenderer extends Component {
render() {
const { route, match, location, staticContext, flattenedRoutes } = this.props;
const { component: RouteComponent } = route;
const { component: RouteComponent, preferLogin = false } = route;
const canShow = this.canShowComponent();
if (!canShow) {
staticContext.forbidden = true;
}
const authPageName = preferLogin ? 'LoginPage' : 'SignupPage';
return canShow
? <RouteComponent
params={match.params}
location={location}
flattenedRoutes={flattenedRoutes}
/>
: <NamedRedirect name="SignupPage" state={{ from: match.url }} />;
: <NamedRedirect
name={authPageName}
state={{ from: `${location.pathname}${location.search}` }}
/>;
}
}