Created
August 8, 2013 19:49
-
-
Save gnomeontherun/6188050 to your computer and use it in GitHub Desktop.
Demonstration of AngularJS and how to define a batch of routes without declaring each directly with $routeProvider.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var routes = [ | |
{ | |
url: '/', | |
params: { | |
templateUrl: 'views/home.html', | |
controller: 'HomeCtrl' | |
} | |
}, | |
{ | |
url: '/bookmarks', | |
params: { | |
templateUrl: 'views/bookmarks.html', | |
controller: 'BookmarksCtrl' | |
} | |
}, | |
{ | |
url: '/search', | |
params: { | |
templateUrl: 'views/search.html', | |
controller: 'SearchCtrl' | |
} | |
} | |
]; | |
angular.module('MyApp', []) | |
.config(function ($routeProvider, $locationProvider) { | |
angular.forEach(routes, function (route, index) { | |
$routeProvider.when(route.url, route.params); | |
}); | |
$routeProvider | |
.otherwise({ | |
redirectTo: '/' | |
}); | |
$locationProvider.html5Mode(true); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment