AngularJS-仅当I';我有某种看法

AngularJS-仅当I';我有某种看法,angularjs,Angularjs,这是我的主js文件的外观: var myApp = angular.module('myApp', ['ngRoute']); myApp.config(['$routeProvider', function ($routeProvider) { $routeProvider.when('/login', { templateUrl: 'partials/login.html', controller:'loginCtrl' }); $r

这是我的主js文件的外观:

var myApp = angular.module('myApp', ['ngRoute']);

myApp.config(['$routeProvider', function ($routeProvider) {
    $routeProvider.when('/login', {
        templateUrl: 'partials/login.html',
        controller:'loginCtrl'
    });
    $routeProvider.when('/categories', {
        title: 'Documents',
        templateUrl: 'partials/categories.html',
        controller:'categoryCtrl'
    });
    $routeProvider.when('/files', {
        templateUrl: 'partials/files.html',
        controller:'filesCtrl'
    });
    $routeProvider.otherwise({ redirectTo: '/login' });
}]);

 myApp.run(function($rootScope, $location) {
    $rootScope.location = $location;
});
我需要实现的是,当我在files.html视图上时,当我刷新页面时,我需要应用程序重定向到categories.html视图

如何才能做到这一点

提前感谢您的时间和建议

编辑:

myApp.run(function($rootScope, $location) {
    $rootScope.location = $location;

    $rootScope.$on('$routeChangeStart', function (event, next, current) {
      if (!current && next.$$route.originalPath == '/files') {
        $location.path('/categories');
      }
    });
});

您可能需要注意页面刷新[查看此解决方案:并发送到那里。希望这有帮助。此外,我认为您可以执行$routeProvider.when('..,{…})。when(…)。when(…)。Others();而不是多个$routeProvider.when(…);调用,这实际上非常有用。谢谢!我编辑了我的问题以包含答案。