【问题标题】:How can I reset browser's navigation history in angular2?如何在 angular2 中重置浏览器的导航历史?
【发布时间】:2016-06-22 05:11:47
【问题描述】:

我想清除 angular2 中的浏览器导航历史记录,以便在用户导航到特定页面(我感兴趣的页面)后,不应通过单击浏览器后退或下一步按钮来后退或前进..... ..

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

 import {Location} from "angular2/router";

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

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

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

但它不起作用。

【问题讨论】:

    标签: angular angular2-routing


    【解决方案1】:

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

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

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

    【讨论】:

    • 谢谢...我意识到我必须通过注入窗口对象和实现 window.onpopstate 事件来实现我自己的自定义 HistoryStrategy...谢谢稍后会做...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-14
    • 2015-10-10
    相关资源
    最近更新 更多