3

I have a problem when trying to navigate to a child view by code using the router object within my component :

this.router.navigate(['./details']); //Error: Cannot match any routes: 'details'

But within my template using routerLink, it works : Test me I need to do the same thing but within the component using the router.navigate method. My component is displayed within another one in a routerOutlet, I have the following sub routing config :

export const HOME_ROUTES: Routes = [
  {
    path: 'home',
    component: HomeComponent,
    children: [{path: '',outlet: 'route1',component: DashboardComponent,pathMatch: 'full'},
    {
        path: 'dashboard',
        outlet: 'route1',
        component: DashboardComponent
    },
    {
        path: 'tasks',
        outlet: 'route1',
        component: TasksComponent,
        children: [
            { path: '',component: TasksListComponent,pathMatch: 'full'},
            { path: 'list',component: TasksListComponent},
            { path: 'details', component: TasksDetailsComponent },
            { path: 'view', component: TasksListComponent },
        ]
      }
    ]
  }
];

And I'm trying to display the TasksDetailsComponent from the TasksListComponent, my relative url is "http://localhost:8000/home/(route1:tasks)

Any help is very appreciated Many thanks

1 Answer 1

5

first

import { ActivatedRoute } from '@angular/router';

then within your component

constructor(private route: ActivatedRoute) {}

then

this.router.navigate(['./details'], { relativeTo: this.route });
Sign up to request clarification or add additional context in comments.

1 Comment

@mthkhaled feel free to accept this answer if it works for you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.