Maison > Questions et réponses > le corps du texte
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('/');
}
};
})
Quand j'ai ouvert la page Web, c'était http://localhost:8000/#/ Lorsque je me suis connecté, je voulais la changer en http://localhost:8000/#/dashb..., mais. après l'opération, le chemin est devenu Comment résoudre http://localhost:8000/?#/
? ?
世界只因有你2017-05-15 17:08:06
Bloquez temporairement votre résolution
resolve: {
"check": function($location, $rootScope) {
if (!$rootScope.loggedIn) {
$location.path('/');
}
}
}
Il est évident ici qu'il est utilisé pour la vérification de la connexion. Si la vérification échoue, il sera redirigé vers http://localhost:8000/?#/
.