Cannot navigate to a route that has redirectTo specified in Angular2 by name

The following paths are defined in My RouteConfig:

@RouteConfig ([
    { path:'/main',name:'Home',redirectTo: ['Setup']},
    { path:'/setup',name:'Setup',component:SetupComponent},
    { path:'/configuration',name:'Configuration',component:ConfigurationComponent},
])

In the template I have

    <ol>
        <li><a [routerLink]="['Setup']">Setup</a></li>
        <li><a [routerLink]="['Configuration']">Configuration</a></li>
        <li><a [routerLink]="['Home']">Home</a></li>                
    </ol>

In the component, in the method I tried

this._Router.navigate(['Home']);

In both cases (using the routerLink directive and the Router.navigate method), when I try to go to the Home route, I get the following error.

Component "AppComponent" has no route named "Home"

While both routes that are connected to them work as expected. The same behavior when they are called from child routers.

How can I route a route to a route identified by the name "Home"?

+4
source share
2 answers

. Home Setup, Setup.

+3

/ this._Router.navigate(['/Home']);

. Angular2

0

Source: https://habr.com/ru/post/1628329/


All Articles