mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-28 12:43:11 +10:00
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:
parent
54e42b7ad8
commit
8d9c078309
1 changed files with 6 additions and 2 deletions
|
|
@ -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}` }}
|
||||
/>;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue