Reputation: 510
The main router's pipeline of my application redirects to login page if a user is not logged in.
It works fine for most pages, but when said page holds itself a child router, the logic does not seem to hit the main router's pipeline, preventing redirection (as well as not rendering the page).
main router:
configureRouter (rc: RouterConfiguration, router: Router) {
this.router = router;
rc.addAuthorizeStep(this.requireAuth);
const auth = { authenticated: true, needsCurrentOrg: true };
const loginRoute = {
route: 'login/:token?',
name: 'login',
moduleId: PLATFORM.moduleName('views/login/login'),
};
rc.map([
{
route: [ROOT_PAGE, DASHBOARD_PAGE],
name: DASHBOARD_PAGE,
moduleId: PLATFORM.moduleName('views/dashboard/dashboard'),
settings: auth
},
{
route: CREDENTIALS_PAGE,
name: CREDENTIALS_PAGE,
moduleId: PLATFORM.moduleName('views/credentials/credentials-root'),
settings: auth
})]
}
credentials router:
configureRouter (rc: RouterConfiguration) {
rc.map([
{
route: '',
name: 'credentials-list',
moduleId: PLATFORM.moduleName('./credentials-grid'),
}
]);
}
So if I hit /#/dashboard
without being logged in, I get redirected to /login
, but nothing happens if I hit /#/credentials
: blank page, no redirection. I put a debugger
in the requireAuth
middle-ware code, and in the first case it does step in, in the second case it does not go through
Upvotes: 1
Views: 35
Reputation: 510
Finally identified the issue, for some reasons it looks like the LoadRouteStep
pipeline step (internal to the AppRouter
) tried to load the ViewModel of the subrouter target.
Since this ViewModel had some code in the constructor, that code was failing, creating an error and stopping the pipeline - never reaching the redirection.
The fix was to move that constructor code into an activate
function for the ViewModel.
Upvotes: 1