Javascript 无法在组件内部使用[routerLink]

Javascript 无法在组件内部使用[routerLink],javascript,angularjs,routes,angular,angular2-routing,Javascript,Angularjs,Routes,Angular,Angular2 Routing,Im有2个,一切正常,这是我的RouteConfig在配置文件组件中: @Component({ selector : "profile", templateUrl: '/client/tmpl/profile.html', directives: [ ROUTER_DIRECTIVES], }) @RouteConfig([ {name: 'Home', component: homeProfile ,path: '/' ,useAsDefault:true

Im有2个
,一切正常,这是我的
RouteConfig
在配置文件组件中:

@Component({
    selector : "profile",
    templateUrl: '/client/tmpl/profile.html',
    directives: [ ROUTER_DIRECTIVES],
})

@RouteConfig([
     {name: 'Home', component: homeProfile ,path: '/' ,useAsDefault:true},
     {name: 'Credit', component: credit ,path: '/credit' },
     {name: 'BuyCredit', component: buyCredit ,path: '/buycredit' }
])
我的问题是当我想在
credit
组件中使用[routerLink]时抛出一个错误: “信用”没有路由配置。在[null]中

这是我的
学分
部分:

import {ROUTER_DIRECTIVES,RouteConfig} from 'angular2/router';
 @Component({
    selector : "credit",
    templateUrl : "client/tmpl/profile/credit.html",
    directives: [ROUTER_DIRECTIVES]

})
模板:

<ul>
                                 <li><a  [routerLink]="['Profile' , 'Home']"  href="#">home</a> </li>
</ul>
为什么我应该在
credit
组件中使用RouteConfig?以及如何使用?

试试这个



如我所见,您已经在主组件中定义了
Profile
路由,然后
Profile
具有子组件,即:
Home

因此,出现异常是因为:

  • 路由链接中的
    Profile
    表示在该组件的routeConfig中查找路由

  • 但是您需要在routerLink中执行
    /Profile
    ,告诉它在根(主组件)的routeConfig中查找
    Profile
    路由


非常感谢