Angular 2 go to root path "/"

I am trying to switch to the home route from the children's route, but nothing happens.

those. current route /projects

this.router.navigate(['/']) routerLink="/" not routerLink="/" , nor routerLink="/" .

My routerConfig is as follows

 const routes: Routes = [ { path: '', component: HomeComponent }, { path: '/projects', component: ProjectsComponent } ] 

How can I do it?

+5
source share
1 answer

Try adding redirectTo to your routes,

 const routes: Routes = [ { path: '', redirectTo: 'home', pathMatch: 'full' }, { path: '/home', component: HomeComponent }, { path: '/projects', component: ProjectsComponent } ]; 
+5
source

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


All Articles