Angular2:锚标签没有href链接,除非重新加载页面

时间:2016-04-15 19:28:08

标签: angular angular2-routing angular2-template

我在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链接,并且效果很好。我应该如何解决这个问题,以便在首次加载后使其正常工作?

0 个答案:

没有答案