0

I'm trying to create file & folder manager using angular-js.
So i need endless optional parameters for folderIds to handling this:
example.com/drive/1/2/3/4/5/...

Do we have something like this:

$routeprovider.when('/drive/[:folderId?]', {
    controller: 'driveCtrl',
    templateUrl: '/app/views/drive.html'
})

instead of this:

$routeprovider.when('/drive/:folderId1?/:folderId2?/:folderId3?/:folderId4?', {
    controller: 'driveCtrl',
    templateUrl: '/app/views/drive.html'
})
MeTe-30
  • 2,512
  • 2
  • 21
  • 30

1 Answers1

1

If you would use angular-ui-router, you could define custom parameter type if you want it to contain slashes, as described here. You can also see this answer.

For example:

$urlMatcherFactory.type("FolderType", {
  encode: function(val) { return val != null ? val.toString() : val; },
  decode: function(val) { return val != null ? val.toString() : val; },
  is: function(val) { return this.pattern.test(val); },
  pattern: /([^/]+\/?)+/ // this should catch /example.com/drive/1/2/3/4/5/ in one param
});

$stateProvider.state('drive', {
  url: '/drive/{folder:FolderType}',
  controller: 'driveCtrl',
  templateUrl: '/app/views/drive.html'
});
Community
  • 1
  • 1
fracz
  • 20,536
  • 18
  • 103
  • 149