在 app bootstrap 中使用 Guard
文件 main.ts (或 boot.ts )
考虑以上示例:
- 创建警卫 ( 创建 Guard 的地方)和
- 为路由配置添加保护,( 为路由配置 Guard,然后导出 APP_ROUTER_PROVIDERS ),
我们可以将 Bootstrap 耦合到 Guard,如下所示
import { bootstrap } from '@angular/platform-browser-dynamic';
import { provide } from '@angular/core';
import { APP_ROUTER_PROVIDERS } from './app.routes';
import { AppComponent } from './app.component';
bootstrap(AppComponent, [
APP_ROUTER_PROVIDERS
])
.then(success => console.log(`Bootstrap success`))
.catch(error => console.log(error));