问题
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' }
])
my problem is when I want use [routerLink] inside the credit component throw an Error:
"credit" has no route config. in [null]
and this is my credit Component :
import {ROUTER_DIRECTIVES,RouteConfig} from 'angular2/router';
@Component({
selector : "credit",
templateUrl : "client/tmpl/profile/credit.html",
directives: [ROUTER_DIRECTIVES]
})
template :
<ul>
<li><a [routerLink]="['Profile' , 'Home']" href="#">home</a> </li>
</ul>
why i should use RouteConfig inside credit Component?and how to use?
回答1:
Try this
<a [routerLink]="['/Profile' , 'Home']" href="#">home</a>
As I see, you have defined Profile route in the Main Component and then Profile has child Components ie: Home.
So, exception occurs because:
Profilein the routerLink means look for the route in this component's routeConfig.but you need to do
/Profilein routerLink to tell it to look forProfileroute in the root(Main Component)'s routeConfig
来源:https://stackoverflow.com/questions/37361254/cant-use-routerlink-inside-the-component