这是我的主要组件的精简版本,它被引导,定义了一条路线。
import { Component } from "angular2/core";
import {
RouteConfig,
ROUTER_DIRECTIVES,
ROUTER_PROVIDERS
} from "angular2/router";
import { DashboardComponent } from "./components/dashboard/dashboard.component";
@RouteConfig([
{
path: "/dashboard",
name: "Dashboard",
component: DashboardComponent,
useAsDefault: true,
},
])
@Component({
selector: "my-app",
templateUrl: "app/app.component.html",
directives: [
ROUTER_DIRECTIVES
],
providers: [
ROUTER_PROVIDERS
]
})
export class AppComponent {}
并且在主要组件的相应HTML中,router-link-active类被添加到活动链接。
<nav class="global-navigation">
<a [routerLink]="['Dashboard']">View All</a>
<a [routerLink]="['Tag',{tagName:'CSS'}]">CSS</a>
</nav>
<main class="main-content">
<router-outlet></router-outlet>
</main>
仪表板组件:
import { Component } from "angular2/core";
import { NotesList } from "../../components/notes-list/notes-list.component";
import { ROUTER_DIRECTIVES } from "angular2/router";
@Component({
selector: "my-dashboard",
templateUrl: "app/components/dashboard/dashboard.component.html",
directives: [NotesList, ROUTER_DIRECTIVES]
})
export class DashboardComponent {}
在仪表板HTML中,路由器链接活动类未添加到活动链接。
<orbital-notes-list></orbital-notes-list>
<a [routerLink]="['Tag', {tagName:'CSS'}]">Testing</a>
<a [routerLink]="['Dashboard']">Back</a>
我找不到解决方案。我肯定错过了一些东西。