angular.js - angularjs的route路径问题
巴扎黑
巴扎黑 2017-05-15 17:06:06
0
2
473
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/?#/
该怎么解决??

巴扎黑
巴扎黑

reply all(2)
刘奇

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

世界只因有你

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template