recherche

Maison  >  Questions et réponses  >  le corps du texte

angulaire.js - Problème de chemin de route angulairejs

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/?#/
? ?

巴扎黑巴扎黑2872 Il y a quelques jours538

répondre à tous(2)je répondrai

  • 怪我咯

    怪我咯2017-05-15 17:08:06

    Il devrait s'agir d'un problème avec l'adresse href d'un lien

    répondre
    0
  • 世界只因有你

    世界只因有你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/?#/

    .

    répondre
    0
  • Annulerrépondre