angularjs – Angular2获取当前路由的别名
发布时间:2020-12-17 07:37:41 所属栏目:安全 来源:网络整理
导读:我可以通过location.path()获取当前路由的路径:/ about,/,/ news. 但是如何取代它的别名(路由的定义中的“as”部分)? { path: '/about',as: 'About',component: About } 可能吗? 注意:以下内容已通过2.0 beta系列测试. RC版本具有更新的路由器组件,具有
我可以通过location.path()获取当前路由的路径:/ about,/,/ news.
但是如何取代它的别名(路由的定义中的“as”部分)? { path: '/about',as: 'About',component: About } 可能吗?
注意:以下内容已通过2.0 beta系列测试. RC版本具有更新的路由器组件,具有突破性的更改.旧的已重新命名为路由器已弃用.这还没有针对新的路由器进行测试.
以下将根据您的活动路线打印Foo或Bar. @Component({ selector: 'app',templateUrl: 'app/app.html',directives: [ROUTER_DIRECTIVES] }) @RouteConfig([ {path:'/',name: 'Foo',component: FooComponent,useAsDefault: true},{path:'/bar',name: 'Bar',component: BarComponent,useAsDefault: false},]) export class AppComponent implements OnInit { constructor(private _router: Router) { } ngOnInit() { console.log('current route name',this._router.currentInstruction.component.routeName); } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |