最近我读了这篇关于Angular 2 Router的有用文章并看了一下这个演示.一切似乎都很完美.但是当我尝试根据router-link-active类确定活动路由时,我发现根路由始终处于活动状态.
以下是app.component.ts的代码段,其中配置了"main"路由:
@Component({
selector: 'demo-app',
template: `
<a [routerLink]="['/']">Home</a>
<a [routerLink]="['/about']">About</a>
<div class="outer-outlet">
<router-outlet></router-outlet>
</div>
`,
// add our router directives we will be using
directives: [ROUTER_DIRECTIVES]
})
@Routes([
// these are our two routes
{ path: '/', name: 'Home', component: HomeComponent }, // , useAsDefault: true}, // coming soon
{ path: '/about', name: 'About', component: AboutComponent }
])
export class AppComponent { }
Run Code Online (Sandbox Code Playgroud)
如果我从改变路径'/',以'/home'和<a [routerLink]="['/']">Home</a>对 …