如何在angular2中重置浏览器的导航历史记录?

时间:2016-03-08 10:02:43

标签: angular angular2-routing

我想在angular2中清除浏览器导航历史记录,以便在用户导航到特定页面(我感兴趣的页面)之后,通过单击浏览器返回或下一个按钮不应该返回或转发..... ..

现在我尝试像这样导入Angular2位置

 import {Location} from "angular2/router";

并像这样使用它来阻止导航

 this._location.replaceState('/'); //clear browser navigation history and reset it to root /
 this._router.navigateByUrl('/home');

注意:假设位置和路由器已正确注入

但它不起作用。

1 个答案:

答案 0 :(得分:0)

浏览器不支持此功能。见JS - window.history - Delete a state

最近创建了一个允许传递自定义HistoryStrategy的问题,该问题应该允许您管理将URL推送到历史记录的方式和时间。

另见https://github.com/angular/angular/issues/3481