我可以通过location.path()获取当前路由的路径:/ about,/,/ news.
但是如何取代它的别名(路由的定义中的“as”部分)?
但是如何取代它的别名(路由的定义中的“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);
- }
- }