给定一个使用
Router
进行导航的应用程序,如何从历史记录中过滤掉特定的路由器历史记录元素?
例如我可以做这样的事情,我可以获取并过滤掉所有带有“xyz”的网址:
// pseudo code
history = this.router.getHistory();
filtered = history.filter(x => !x.url.contains('xyz'));
this.router.setHistory(filtered);
目标是浏览器的历史记录现在不应包含“xyz”url,因此如果按“后退”,则不应导航“xyz”url,即使它们以前位于历史记录中。
添加
skipLocationChange: true
作为导航选项
// Navigate silently to /example
this.router.navigate(['/example'], { skipLocationChange: true });