asu*_*sky 10 javascript angular
最近我读了这篇关于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>对<a [routerLink]="['/home']">Home</a>(它必须是HomeComponent)默认组件消失.只有在单击链接时才会激活HomeComponent,router-link-active并且每次我们更改为另一个路径时都会正确添加和删除HomeComponent.
这是一个错误还是路由配置有问题?
小智 23
将以下属性添加到您的主锚为我工作.
[routerLinkActiveOptions]="{ exact: true }"
了解更多https://github.com/angular/angular/issues/8397#issuecomment-237314970
| 归档时间: |
|
| 查看次数: |
3233 次 |
| 最近记录: |