Lazy load modules on same path based on role

本秂侑毒 提交于 2020-01-16 05:14:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!