Option I: with static init of all possible routes
Something like this could work, although this is using app.config but in a programmatic way.
angular.module('yourApp',['ngRoute']).config(function ($routeProvider) {
// get your pages from somewhere (e.g. via $http)
var yourBigChunkOfPages = [
{route: ..., template: ..., ctrl: ...},
...
];
angular.forEach(yourBigChunkOfPages, function (page) {
$routeProvider.when(page.route, {
template: page.template,
controller: page.ctrl
});
});
});
Option II: with dynamic routing to single controller
Another, probably more generic, solution could be loading the same controller for all your requests and decide there what to do. E.g.:
angular.module('yourApp',['ngRoute']).config(function ($routeProvider) {
$routeProvider.when("/page/:pagename", {
template: 'page.html',
controller: 'PageCtrl'
});
})
.controller('PageCtrl', function ($scope, $routeParams) {
// do something with $routeParams.pagename which holds
// the reference to the requested pagename
});
There is an explainaition of how to work with the injected params.
module. Each module now will have it's ownroutes. This way you end up with chunkable sizes of code and easy to understand app