angularjs – Angular2获取当前路由的别名

前端之家收集整理的这篇文章主要介绍了angularjs – Angular2获取当前路由的别名前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我可以通过location.path()获取当前路由的路径:/ about,/,/ news.
但是如何取代它的别名(路由的定义中的“as”部分)?
  1. { path: '/about',as: 'About',component: About }

可能吗?

注意:以下内容已通过2.0 beta系列测试. RC版本具有更新的路由器组件,具有突破性的更改.旧的已重新命名为路由器已弃用.这还没有针对新的路由器进行测试.

以下将根据您的活动路线打印Foo或Bar.

  1. @Component({
  2. selector: 'app',templateUrl: 'app/app.html',directives: [ROUTER_DIRECTIVES]
  3. })
  4. @RouteConfig([
  5. {path:'/',name: 'Foo',component: FooComponent,useAsDefault: true},{path:'/bar',name: 'Bar',component: BarComponent,useAsDefault: false},])
  6. export class AppComponent implements OnInit {
  7. constructor(private _router: Router) {
  8. }
  9.  
  10. ngOnInit() {
  11. console.log('current route name',this._router.currentInstruction.component.routeName);
  12. }
  13. }

猜你在找的Angularjs相关文章