问题描述
在我的应用程序中,我有一个类别页面,其中包含指向各种产品列表页面的链接.如果事实证明当您进入产品列表页面时只有一个产品,那么它会自动导航到该产品详细信息页面.我想要的是删除历史记录中的产品列表页面路由,以便当用户在产品详细信息页面上并点击后退按钮时,他们将转到类别页面而不是产品列表页面,因为这只会将他们重定向回来到详细信息页面.
In my app I have a category page that has links to a various product list pages. If it turns out that when you get to a product list page there is only one product then it automatically navigates to that product detail page. What I want is to remove the product list page route in the history so that when the user is on the product detail page and hits the back button they will go to the category page and not the product list page because that will just redirect them back to the detail page.
推荐答案
您可以使用角度路由器 replaceUrl
标志来执行此操作.有关详细信息,请参阅 api 文档此处
You can use angular routers replaceUrl
flag to do this. See api docs for more details here
this.router.navigate(['/view'], { replaceUrl: true });
这篇关于在 Angular 中,如何从导航历史记录中删除当前路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!