var app = angular.module('myApp', ['ngRoute']);
app.config(function($routeProvider) {
$routeProvider.when('/', {
templateUrl: 'login.html',
})
.when('/dashboard', {
resolve: {
"check": function($location, $rootScope) {
if (!$rootScope.loggedIn) {
$location.path('/');
}
}
},
templateUrl: 'dashboard.html'
})
.otherwise({
redirectTo: '/'
});
});
app.controller('loginCtrl', function($scope, $location, $rootScope) {
$scope.submit = function() {
if ($scope.username == 'admin' && $scope.password == 'admin') {
$rootScope.loggedIn = true;
$location.path('/dashboard');
} else {
alert('Wrong!');
$location.path('/');
}
};
})
When I opened the web page, it was http://localhost:8000/#/. When I logged in, I wanted to change it to http://localhost:8000/#/dashb..., but after the operation, the path became How to solve http://localhost:8000/?#/
? ?
It should be a problem with the href address of a link
Temporarily block your resolve
It is obvious here that it is used for login verification. If the verification is unsuccessful, it will be redirected to http://localhost:8000/?#/