Reputation: 130
This Piece of code works absolutely fine with cdn https://ajax.googleapis.com/ajax/libs/angularjs/1.2.3//angular-route.min.js
but not with https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6//angular-route.min.js
Where is the issue?
config.js
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'
});
}]);
Upvotes: 0
Views: 676
Reputation: 1
See $location
Starting with 1.3 you need to specify the base url. And remove the / from your routes, ie:
.when('/viewStudents' should be .when('viewStudents'
<head>
<base href="/">
...
</head>
Or set requireBase to false
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
Prior to 1.3, what you have would work when deployed to root context--but would not work in a subcontext.
Upvotes: 0
Reputation: 366
well, this might not be considered as answer you're looking for, but I was struggling exactly with the same problem and since then I'm using $stateProvider which works like a charm
the syntax is very similar
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,
})
and so on
Upvotes: 0