标签: angular-canload

canLoad 使用 NgRx 加载子路由

我正在 Angular 9 应用程序中工作,并且仅当我的应用程序状态 (ngrx) 具有属性 != null 时,我才尝试加载(或不加载)特定模块

首先,我的路线中有一个 AuthGuard,但带有 canActivate。所以我希望“仪表板”模块仅在 mt AppState 有令牌时加载

这是我的路线文件

const routes: Routes = [
{
  path: '',
  component: AppLayoutComponent,
  canActivate: [ AuthGuard ],
  children: [
    { path: '',  loadChildren: () => import('./pages/modules/dashboard/dashboard.module').then(m => m.DashboardModule) }
  ]
},
{
  path: '',
  component: AuthLayoutComponent,
  children: [
    { path: 'session',  loadChildren: () => import('./pages/modules/session/session.module').then(m => m.SessionModule) }
  ]
},
{
  path: '**',
  redirectTo: 'session/not-found'
}];
Run Code Online (Sandbox Code Playgroud)

这是我的 AuthGuard。它 localestorage 没有会话,然后重定向到登录页面。

@Injectable()
export class AuthGuard implements CanActivate { …
Run Code Online (Sandbox Code Playgroud)

angular-routing ngrx angular ngrx-store angular-canload

5
推荐指数
1
解决办法
1716
查看次数