![](/img/trans.png)
[英]Angular - RouterLinkActive is not working when formControlName is added
[英]Angular routerLinkActive not working when navigating using skipLocationChange
假设我有以下路线:
const routes: Routes[] = [
{
path: 'a',
component: AComponent
},
{
path: 'b',
component: BComponent
}
]
在这样的路径上,我a
一些与routerLinkActive
类的 Navbar 链接:
<li
[routerLinkActiveOptions]="{exact: true}"
routerLinkActive="is-active"
class="BottomBar-menuItem"
>
<a routerLink="../a">A</a>
</li>
当我使用skipLocationChange
从路径a
导航到路径b
时出现问题
//component A
navigate() {
this.router.navigate(['../b'], { skipLocationChange: true, relativeTo: this.activatedRoute })
}
浏览器 url 没有改变,它仍然在/a
上,视图更改为组件 B,但routerLinkActive
不应用is-active
类。
routerLinkActive
应该仍然应用is-active
类,因为 url 不会改变,对吗? 我在这里错过了什么?
发生这种情况是因为您使用了“ skipLocationChange: true ”并跳过了 URL 中的位置更改,您可以在以下位置看到一个示例:
https://stackblitz.com/edit/angular-skiplocationchange
和角度文档: https ://angular.io/api/router/NavigationExtras
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.