Question

I want to build something like a directory browser with AngularJS. Is is possible to route paths with ng-route? I'd like to parse URLs like this: myapp.com/#/folder1/folder2/.../folderN

Was it helpful?

Solution

From $routeProvider docs

path can contain named groups starting with a colon and ending with a star: e.g.:name*. All characters are eagerly stored in $routeParams under the given name when the route matches.

So you could define

$routeProvider.when('/:folders*', {
    template:'template'
})

And then (in controller e.g.)

$rootScope.$on('$routeChangeSuccess', function(event, current, previous) {
    if (angular.isDefined($routeParams.folders))
        var foldersArray = $routeParams.folders.split('/');
});

DEMO JSFIDDLE: http://jsfiddle.net/rYm5G/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top