从链接Angular 6重定向另一个页面的指定选项卡中 [英] Redirect in a specified tab in another page from link Angular 6
问题描述
我正在使用Angular 6.2&角材料.
I'm working with Angular 6.2 & Angular Material.
我的页面上有Mat标签(3个标签).
I have a page with mat tabs (3 tabs).
是否可以在此页面中重定向,但第3个标签处于活动状态?通过单击导航栏中的链接.
It is possible to redirect in this page but with the 3rd tab active? From clicking a link in the navbar.
似乎不可能,网站上对此没有任何解决方案.
It looks like not possible, there isn't any solution for this on websites.
推荐答案
我找到了一个很好的解决方案:
I found a good solution:
我使用queryParams
I use queryParams
<a routerLink="/account" [queryParams]="{ tab: 'notifications'}">Link</a>
然后,如果有&标签,我将我的标签设置为活动状态它的价值=通知:
Then I set my tab active if there is tab & it's value = notifications:
[active]="tab && tab === 'notifications'"
在控制器中,如果有queryparams,则设置选项卡(this.tab)并将其删除,所以我永远不会看到
In the controller I set tab (this.tab) if there is queryparams and I remove it so I never see
?tab =通知
?tab=notifications
在我的网址中.
ngOnInit() {
this.activatedRoute.queryParams.subscribe((params) => {
if (params.tab) {
this.tab = params.tab;
this.route.navigate([], {
queryParams: {
tab: null,
},
queryParamsHandling: 'merge',
});
}
});
}
这篇关于从链接Angular 6重定向另一个页面的指定选项卡中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!