I am working on a fairly simple AngularJS project with some nesting depth for routes to select from a nested data structure:
angular.module('doccat', []). config(['$routeProvider', function($routeProvider) { $routeProvider. when('/', { templateUrl: 'partials/detail.html', controller: DocDetailCtrl }). when('/:p0', { templateUrl: 'partials/detail.html', controller: DocDetailCtrl }). when('/:p0/:p1', { templateUrl: 'partials/detail.html', controller: DocDetailCtrl }). when('/:p0/:p1/:p2', { templateUrl: 'partials/detail.html', controller: DocDetailCtrl }). when('/:p0/:p1/:p2/:p3', { templateUrl: 'partials/detail.html', controller: DocDetailCtrl }). when('/:p0/:p1/:p2/:p3/:p4', { templateUrl: 'partials/detail.html', controller: DocDetailCtrl }). otherwise({ redirectTo: '/' }); }]); function DocDetailCtrl($scope, $routeParams) { var path = []; if ($routeParams.p0) path.push($routeParams.p0); if ($routeParams.p1) path.push($routeParams.p1); if ($routeParams.p2) path.push($routeParams.p2); if ($routeParams.p3) path.push($routeParams.p3); if ($routeParams.p4) path.push($routeParams.p4); // do stuff with path }
There should be up to 5 layers on the way, which should be enough for my purposes, so at the moment this is good enough. However, the underlying data can be nested arbitrarily deeply, which will require arbitrary routing.
I think that the ideal route would be that it says "the rest of the path goes to any set of parameters", but it doesn't seem like there is a way to do something like this in AngularJS. Just for the sake of completeness, does anyone know how to do this?
source share