在我的控制器中,我有一个这样的重定向,从登录页面到索引页面。
var loginApp = angular.module('angularRestfulAuth', ['ngCookies', 'ngStorage',
'ngRoute',
'angular-loading-bar']);
loginApp
.controller('HomeCtrl', ['$rootScope', '$scope', '$location','$cookies','$window', 'Main', function($rootScope, $scope, $location,$cookies, $window,Main) {
$scope.signin = function() {
var formData = {
username: $scope.username,
password: $scope.password
}
Main.signin(formData, function(res) {
if (res.type == false) {
alert(res.data) ;
} else {
//location.href='/index';
$window.location.assign('/index');
}
}, function() {
$rootScope.error = 'Failed to signin';
})
};
app.js看起来像,
angular.module('angularRestfulAuth', [
'ngStorage',
'ngRoute',
'angular-loading-bar'
])
.config(['$routeProvider', '$httpProvider','$cookies','$locationProvider', function ($routeProvider, $httpProvider,$cookies,$locationProvider) {
$routeProvider.
when('/index', {
templateUrl: 'app/partials/index.html',
controller: 'myController'
}).
when('/signin', {
templateUrl: 'app/partials/signin.html',
controller: 'HomeCtrl'
}).
otherwise({
redirectTo: '/'
});
$locationProvider.html5Mode(true);
如果我使用,location.href='/index';
然后,
http://localhost:5000/index
错误:无法GET / index
如果我使用,$location.url('/index');
然后,
http://localhost:5000/#/index
但仍然显示登录页面,而不是索引页面。