问题描述
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/?#/该怎么解决??
问题解答
回答1:应该是a链接 href地址的问题吧
回答2:暂时屏蔽你的resolve
resolve: {'check': function($location, $rootScope) { if (!$rootScope.loggedIn) {$location.path(’/’); }} }
这里很明显,是做登陆校验的,校验不成功会重定向至http://localhost:8000/?#/

