search

Home  >  Q&A  >  body text

angular.js - angularjs的route路径问题

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('/');
        }
    };
})

我打开网页的时候是http://localhost:8000/#/ ,登陆的时候是想变成 http://localhost:8000/#/dashb... ,但是进行操作后路径却变成了http://localhost:8000/?#/
该怎么解决??

巴扎黑巴扎黑2744 days ago468

reply all(2)I'll reply

  • 怪我咯

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

    It should be a problem with the href address of a link

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-15 17:08:06

    Temporarily block your resolve

    resolve: {
                    "check": function($location, $rootScope) { 
                        if (!$rootScope.loggedIn) {
                            $location.path('/');
                        }
                    }
                }

    It is obvious here that it is used for login verification. If the verification is unsuccessful, it will be redirected to http://localhost:8000/?#/

    reply
    0
  • Cancelreply