2016-06-09 47 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,你有什么在部署到根上下文会工作 - 但不会在工作子上下文。