【发布时间】:2015-12-05 10:28:38
【问题描述】:
在我的应用程序是用 jQuery 编写并且不是 SPA 之前。我已经将一些页面重写为 AngularJS 并使其成为 SPA。
现在我需要在这些应用程序之间进行适当的通信。 因为当我从 Angular 页面转到 Angular 页面时,我不想重新加载页面,但是当我转到 jQuery 页面时,我确实想重新加载页面,以便服务器可以向我发送其他源文件。强>
因此,当链接转到 Angular 页面(来自 Angular 页面)时,很简单:
<a href="store/categories">
并且ui-router 捕获"store/categories",更改状态并且它不会重新加载页面。
但是,如果链接转到 jQuery 页面(来自 Angular 页面),我不能只指定 <a href="store/categories">,因为 ui-router 会捕获它并且页面不会重新加载。
然后我决定使用window.location.href强制页面重新加载:
<a href="store/categories" ng-click="$root.newHref('store/categories')">
$rootScope.newHref = function(url) {
var url = ROOT_URL + urlBody; // ROOT_URL is just a protocol with host name
window.location.href = url;
};
它奏效了!当您现在单击该链接时,它将使用正确的 URL 重新加载页面。
但是,如果您使用window.location.href 访问页面,然后单击浏览器返回按钮,URL 将更改,但页面不会重新加载。
我该如何解决?
【问题讨论】:
标签: javascript jquery html angularjs angular-ui-router