[英]routerLinkActive does not work with router.navigateByUrl or navigate
I am changing the route through a (click)
and not a [routerLink]
and this is not add class active but change the route我正在通过
(click)
而不是[routerLink]
更改路线,这不是添加类活动而是更改路线
I have to generate an id in the server and after that run this.router.navigate
and activate the link in my side menu我必须在服务器中生成一个 id,然后运行
this.router.navigate
并激活我侧菜单中的链接
<li
routerLinkActive="active"
[routerLinkActiveOptions]="{exact: false}">
<a
class="nav-link"
(click)="addNew()"
>
</a>
</li>
my function我的功能
addNew(): void {
this.userService.create().subscribe(res => {
this.router.navigateByUrl(`user/edit/${res.data.id}`);
});
}
Other places in the menu are using [routerLink] and it works normally菜单中的其他地方都在使用[routerLink],它工作正常
thanks for help感谢帮助
routerLinkActive
relies on having a routerLink
on either the same host or a descendant in order to know what the candidate links are. routerLinkActive
依赖于在同一主机或后代上有一个routerLink
来知道候选链接是什么。
You need to add a routerLink
to your <a>
.您需要将
routerLink
添加到您的<a>
。
<li routerLinkActive="active" [routerLinkActiveOptions]="{exact: false}">
<a routerLink="???" class="nav-link" (click)="addNew()">
</a>
</li>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.