【发布时间】:2017-09-16 16:25:52
【问题描述】:
我在我的应用路由模块中定义了一些路由数据,如下所示:
const appRoutes:Routes = [
{path: '', component: LoginComponent, data:[{PageName:"Login Page"}]}]
我想全局获取数据,这样我就可以使用app.component.ts中的appRoutes来获取URL重定向相关信息如下:
export class AppComponent {
title = 'Welcome';
constructor(public router: Router, public authenticationService: AuthenticationService) {
this.router.events.subscribe(event => {
console.log("Url",event.urlAfterRedirects);
console.log("Page Name", router[PageName]); //Not working
}
我尝试注入 ActivatedRoute,但每次重定向后它都没有更新。
无论如何,我可以在哪里配置页面名称并在全局app.component.ts 中获取它。
【问题讨论】:
标签: javascript angular typescript angular-routing