user5738822
user5738822

Reputation:

cant use [routerLink] inside the component

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?

Upvotes: 2

Views: 1709

Answers (1)

Ankit Singh
Ankit Singh

Reputation: 24955

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:

  • Profile in the routerLink means look for the route in this component's routeConfig.

  • but you need to do /Profile in routerLink to tell it to look for Profile route in the root(Main Component)'s routeConfig

Upvotes: 1

Related Questions