Javascript 无法在组件内部使用[routerLink]
Im有2个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
,一切正常,这是我的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
因此,出现异常是因为:
- 路由链接中的
表示在该组件的routeConfig中查找路由Profile
- 但是您需要在routerLink中执行
,告诉它在根(主组件)的routeConfig中查找/Profile
路由Profile