标签:dashboard str 解析 优点 round popup code 增加 message
// 使用无组件路由,即分组路由,可以不需要用来只管理分组路由的组件 const adminRoutes: Routes = [ { // path: ‘admin‘ 更改为 ‘‘; path: ‘‘, component: AdminComponent, canActivate: [AuthGuard], children: [ { path: ‘‘, canActivateChild: [AuthGuard], children: [ { path: ‘crises‘, component: ManageCrisesComponent}, { path: ‘heroes‘, component: ManageHeroesComponent}, { path: ‘‘, component: AdminDashboardComponent} ] } ] } ];
// loadChildren 接收函数;使用动态导入来懒加载代码;当代码请求并加载完毕后,这个promise会解析成一个NgModule 对象;即AdminModule const routes: Routes = [ { path: ‘compose‘ , component: ComposeMessageComponent, outlet: ‘popup‘}, { path: ‘admin‘, loadChildren: () => import(‘./admin/admin.module‘).then(mod => mod.AdminModule)}, { path: ‘‘, redirectTo: ‘heroes‘, pathMatch: ‘full‘ }, { path: ‘**‘, component: PageNotFoundComponent } ];
//... // import { AdminModule} from ‘./admin/admin.module‘; //... imports: [ BrowserModule, FormsModule, HeroesModule, CrisisCenterModule, // AdminModule, AuthModule, AppRoutingModule, BrowserAnimationsModule ], //....
// auth.guard.ts 中 新增方法 // 路由器会将route 参数 设置为 准备访问的目标URL;如果用户登录,就会重定向到这个URL canLoad(route: Route): boolean { let url = `/${route.path}`; return this.checkLogin(url); }
import { NgModule } from ‘@angular/core‘; import { RouterModule, Routes } from ‘@angular/router‘; import { ComposeMessageComponent } from ‘./compose-message/compose-message.component‘; import { PageNotFoundComponent } from ‘./page-not-found/page-not-found.component‘; import { AuthGuard } from ‘./auth/auth.guard‘; import { SelectivePreloadingStrategyService } from ‘./selective-preloading-strategy.service‘; const appRoutes: Routes = [ { path: ‘compose‘, component: ComposeMessageComponent, outlet: ‘popup‘ }, { path: ‘admin‘, loadChildren: () => import(‘./admin/admin.module‘).then(mod => mod.AdminModule), canLoad: [AuthGuard] }, { path: ‘crisis-center‘, loadChildren: () => import(‘./crisis-center/crisis-center.module‘).then(mod => mod.CrisisCenterModule), data: { preload: true } }, { path: ‘‘, redirectTo: ‘/superheroes‘, pathMatch: ‘full‘ }, { path: ‘**‘, component: PageNotFoundComponent } ]; @NgModule({ imports: [ RouterModule.forRoot( appRoutes, { enableTracing: false, // <-- debugging purposes only preloadingStrategy: SelectivePreloadingStrategyService, } ) ], exports: [ RouterModule ] }) export class AppRoutingModule { }
标签:dashboard str 解析 优点 round popup code 增加 message
原文地址:https://www.cnblogs.com/gushiyoyo/p/11275980.html