javascript - angularjs正常导航而不是$location.path

标签 javascript angularjs

在 Controller A 中,我执行 $location.path('/home'),但实际上我想要一个正常的重定向。 $location.path 不会重新加载页面。我知道在 ui-route 中有 $state.go({reload:true}),但是如何用普通的 ngRoute 做到这一点?我愿意

.controller('home', function($route){
$route.reload()
}

我有一个无限循环。

最佳答案

您可以使用窗口对象来重新加载,而不是$location.path('/path');:

window.location = '/path';

如果你想使用ngRoute,你可以在routeChange上重新加载页面:

myApp.run(['$route', '$rootScope', function ($route, $rootScope) {
    return $rootScope.$on('$routeChangeStart', function (event, next, current) {
        $route.reload();
    });
}]);

关于javascript - angularjs正常导航而不是$location.path,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41185072/

相关文章:

angularjs - session 到期时 SPA 重新登录

angularjs - 尝试从 Angular 中的 'offsetWidth' 方法启动 Google map 时出现错误无法读取属性 "run"

javascript - 为什么不在 Protractor 中使用 executeScript 创建对象

javascript - 破解 AngularJS 表单元素以更改值

javascript - 如何使网页中的图标闪烁/闪烁

JavaScript 按钮不适用于 HTTPS 连接

Javascript数组拼接导致内存不足异常?

css - 修改具有 ng-repeat 和属性集运行时的指令模板的 DOM

javascript - 为什么 boolean 原语不调用原型(prototype) toString()?

javascript - Ext JS - 将面板绑定(bind)到数据存储的最佳方式