不能在组件内部使用[routerLink] [英] cant use [routerLink] inside the component
问题描述
我有2个< router-outlet>
并且一切正常,这是我的 RouteConfig
:
Im have 2 <router-outlet>
and everything is ok,this my RouteConfig
inside the profile component:
@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' }
])
我的问题是我想使用[routerLink]在 credit
组件内抛出错误:
credit没有路由配置。在[null]
my problem is when I want use [routerLink] inside the credit
component throw an Error:
"credit" has no route config. in [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 ?以及如何使用?
why i should use RouteConfig inside credit
Component?and how to use?
推荐答案
尝试一下
<a [routerLink]="['/Profile' , 'Home']" href="#">home</a>
如我所见,您已经定义了个人资料
路线,然后个人资料
具有子成分,即: Home
。
As I see, you have defined Profile
route in the Main Component and then Profile
has child Components ie: Home
.
因此,发生异常是因为:
So, exception occurs because:
-
<$在routerLink中的c $ c> Profile 意味着在该组件的routeConfig中查找路由。
Profile
in the routerLink means look for the route in this component's routeConfig.
,但是您需要执行<$在routerLink中访问c $ c> / Profile ,告诉它在根(主组件)的routeConfig中查找 Profile
路由
but you need to do /Profile
in routerLink to tell it to look for Profile
route in the root(Main Component)'s routeConfig
这篇关于不能在组件内部使用[routerLink]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!