简体   繁体   English

使用$ routeProvider停止window.history.pushState上的ajax请求

[英]Stop the ajax request on window.history.pushState using $routeProvider

I'm using $routeProvider with html5Mode in my application. 我使用$routeProviderhtml5Mode在我的应用程序。

My problem is that if I use this option to change my URL without reloading the site window.history.pushState('page2', 'Title', '/page2.php'); 我的问题是,如果我使用此选项更改我的URL而不重新加载站点window.history.pushState('page2', 'Title', '/page2.php');

The angular does not reload BUT the $routeProvider loads the new url. 角度不会重新加载, 但是 $routeProvider会加载新的URL。

As you can see in the image: 如您在图像中看到的: 在此处输入图片说明

I wonder how I can change the url without the angular do a request of that url. 我不知道如何在不更改角度的情况下更改该网址。

I know there functions to prevent reload the page but none avoid the request of the new url. 我知道有防止重新加载页面的功能,但没有一个功能可以避免请求新的网址。

My problem is that I can stop the page reload, but can not stop the ajax request. 我的问题是我可以停止页面重新加载,但是不能停止ajax请求。

I can't give you details, because I don't know angular :) but in theory you could update the router (routeProvider) to have a global action for /* for example and detect the pushState event there. 我无法提供详细信息,因为我不知道angular :),但是从理论上讲,您可以更新路由器(routeProvider)以使其具有针对/ *的全局操作,并在那里检测pushState事件。 You can do that by setting a flag on pushState or by looking to the onpopstate "event". 您可以通过在pushState上设置标志或查看onpopstate“事件”来实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM