Code
Code

Reputation: 325

How can I load child route with navigate by URL?

I have a child route. I've tried to route to this child route,but without success. If I put this route outside the children array (as independent route) then it works, but not in the children array. Router outlet tag is also in the parent HTML template. What am I doing wrong?

  {path:'adminpanel',component:AdminPanelComponent,canActivate:[AuthGuard],data :{permittedRoles:['Admin']},
  children:[
//it des not work here
    {path:'specific-role-section/:roleId' , component:SpecificRoleSectionComponent}
  ]},
//it works here
  // {path:'specific-role-section/:roleId' , component:SpecificRoleSectionComponent}


//the caller method
 openRoleSection(roleId:string)
  {
    // this.router.navigateByUrl(`specific-role-section/${roleId}` ,  {relativeTo: this.activatedRoute})
    this.router.navigate([`specific-role-section/${roleId}`] ,  {relativeTo: this.activatedRoute})
  }


Upvotes: 0

Views: 921

Answers (1)

Dipten
Dipten

Reputation: 1066

Problem seems on your caller method. Modify navigate method as below.

//the caller method
 openRoleSection(roleId:string)
  { 
    // Try this way
    this.router.navigateByUrl(`adminpanel/specific-role-section/${roleId}` ,  {relativeTo: this.activatedRoute});

    this.router.navigate([`adminpanel/specific-role-section/${roleId}`] ,  {relativeTo: this.activatedRoute})
  }

Upvotes: 1

Related Questions