如何解决此routerLink问题?在page.ts中有什么我没做的吗?
信息中心路线
{path:'ticket', component: ComposeEmailComponent,canActivate: [AuthGuard],
children:[
{
path:'openticket', component:OpenTicketComponent
},
{
path:'chat/:id', component: AgentChatPageComponent
}
]
},
page.html中
//this routes to the page i want to go
<a class="btn btn-success " title="Chat" [routerLink]="['../chat', Page.id]" ><em class="fa fa-whatsapp"></em></a>
page.ts
//this line gives an error that the route doesn't match any routes.
this.router.navigate(['../chat', Page.id]);
ActivatedRoute
constructor(private httpService:HttpService, private route:ActivatedRoute,
private router:Router ){}
答案 0 :(得分:2)
通过在../
函数中指定{ relativeTo: this.activatedRoute }
,您已明确说明您当前的路线导航应为relativeTo
当前已激活的路线(因为路线中有router.navigate
)。
//make sure you injected ActivatedRoute dependency before using it in `navigate` function.
this.parentRouter.navigate(['../chat', Page.id], { relativeTo: this.activatedRoute });