【发布时间】:2016-02-04 21:58:34
【问题描述】:
我的控制器中有一个函数可以更改浏览器的 URL,但是当用户单击后退按钮时,我需要保留真正的上一页。
例如:
用户在 /home 并导航到 /article1。当用户在页面中滚动时,我会更改 URL,例如 /article2 使用:
$location.path('article2');
但是如果用户在 /article2 中按下返回浏览器按钮,则 url 将更改为 /article1,我真的需要将导航重定向到 /home。
我用过这段代码:
var previousPage = document.referrer; // Get the previous location on page load
history.pushState({}, '', previousPage); // Alter the history adding the previous page
但它不起作用,因为在使用 $location 更改 url 时,历史状态会自动更改。
如何保留导航?
【问题讨论】:
标签: javascript angularjs browser-history