问题
I am trying to load an Angular Module based on my role (when I am logged in). I tried it with an Angular Guard but that is not working, when it fails it does not go to the next route.
const routes: Routes = [
{
path: '',
loadChildren: () => AuthModule
// Load when not logged in
},
{
path: '',
loadChildren: () => AdminModule
// Load when admin
},
{
path: '',
loadChildren: () => CrewModule
// Load when crew
}
];
Any ideas for how to fix this? I think an Angular Guard or using a matcher is not the right solution for this...
Edit: For each path/module I have my own guard looking like the following:
import { Injectable } from '@angular/core';
import { CanLoad, CanActivate, Route, Router } from '@angular/router';
import { AuthService } from '@app/core';
@Injectable()
export class AdminModuleGuard implements CanLoad {
constructor(private authService: AuthService, private router: Router) {}
canLoad(route: Route): boolean {
const url: string = route.path;
console.log('Admin Module Load Guard - Url:' + url);
return false;
}
}
Thanks!
Kind regrands, Yanick
来源:https://stackoverflow.com/questions/53378649/lazy-load-modules-on-same-path-based-on-role