2016-06-09 49 views
0

的代碼這幅作品與CDN https://ajax.googleapis.com/ajax/libs/angularjs/1.2.3//angular-route.min.js 但與https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6//angular-route.min.js
在哪裏的問題絕對優良的工作?
config.jsAngularjs路由選擇不與版本1.5.6

var mainApp = angular.module("mainApp", ['ngRoute']); 
    mainApp.config(['$locationProvider','$routeProvider',function($locationProvider,$routeProvider) 
    { 
    // $locationProvider.hashPrefix('!'); 
    $routeProvider 
      .when('/home', { 
       templateUrl: 'home.html', 
       controller: 'StudentController' 
      }) 
      .when('/viewStudents', { 
       templateUrl: 'viewStudents.html', 
       controller: 'StudentController' 
      }) 
      .otherwise({ 
       redirectTo: '/home' 
      }); 
    }]); 

回答

0

好,這可能不被認爲是你要找的答案,但我同樣的問題恰好掙扎,從那時起我使用$ stateProvider其工作方式魅力

的語法非常相似

angular 

    .module('app.routes', ['ionic']) 
    .config(routing); 

function routing($stateProvider, $urlRouterProvider) { 

    $urlRouterProvider.otherwise('/home') 

    $stateProvider 

    .state('layout', { 
     abstract: true, 
     templateUrl: 'views/layout.html', 
     controller: 'myCtl1', 
     controllerAs: 'vm', 
     bindToController: true, 
    }) 

    .state('login', { 
     url: '/login', 
     cache: 'false', 
     templateUrl: 'views/login.html', 
     controller: 'myCtl2', 
     controllerAs: 'vm', 
     bindToController: true, 
    }) 

0

請參閱$location

從1.3開始,您需要指定基礎URL。從你的路線,即刪除/:

.when('/viewStudents' should be .when('viewStudents' 
<head> 
    <base href="/"> 
    ... 
</head> 

或者設置requireBase假

$locationProvider.html5Mode({ 
    enabled: true, 
    requireBase: false 
}); 

此前1.3,你有什麼在部署到根上下文會工作 - 但不會在工作子上下文。