文件main.ts(或boot.ts)
考虑上面的示例:
创建防护(创建防护的位置)并
将Guard添加到路由配置中(将Guard配置为路由,然后导出APP_ROUTER_PROVIDERS),
我们可以将引导程序耦合到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));