我在navigation.component.html
中定义了一个链接
<a [routerLink]="['Dashboard']">
navigation
组件就像
import {ROUTER_DIRECTIVES} from 'angular2/router';
@Component({
selector: 'my-nav',
templateUrl: 'app/layout/navigation.component.html',
styleUrls: ['app/layout/navigation.component.css'],
directives: [ROUTER_DIRECTIVES]
})
export class NavigationComponent {
}
路由配置在另一个组件中,如
import { DashboardComponent } from '../dashboard/dashboard.component';
@Component({
selector: 'my-route-dispatcher',
templateUrl: 'app/components/dispatcher/route-dispatcher.component.html',
directives: [ROUTER_DIRECTIVES, NavigationComponent]
})
@RouteConfig([
{
path: '/dashboard',
name: 'Dashboard',
component: DashboardComponent,
useAsDefault: true
},
])
它的相应模板就像
<db2nav></db2nav>
<router-outlet></router-outlet>
问题在于,当我第一次加载页面时,navigation.component
中的链接无效,<a>
根本没有href
链接。如果我刷新此页面,则<a>
具有正确的href
链接,并且效果很好。我应该如何解决这个问题,以便在首次加载后使其正常工作?