2

In my angularjs app, there is a concept of 'project'. Each project can contain 0 or more folders, and each of those folders can contain 0 or more subfolders. Each of the subfolders, in turn, can contain 0 or more sub-subfolders and so on. There is no actual limit on the amount of folder levels in the hierarchy.

I want to map each of the folder levels to a UIRouter state level.

E.g.,

URL                                                                        State name
http://localhost:8079/projects/1122024                                  -> _.projects.view
http://localhost:8079/projects/1122024/folders/123890                   -> _.projects.view.folder
http://localhost:8079/projects/1122024/folders/123890/547938            -> _.projects.view.folder.folder
http://localhost:8079/projects/1122024/folders/123890/547938/124890     -> _.projects.view.folder.folder.folder

etc.

Is it possible to declare such an endless hierarchy in UIRouter? If yes, then how? The only idea I have now is to use string.split, like following code - but I really don't feel like it's the correct way to do it. Any ideas?

.state('_.projects.view', {
    url: '/{projectId:int}'
})
.state('_.projects.view.folders', {
  url: '/folders/{folderIds}',
  resolve: {
    folderIdTree: function($stateParams) {
      $stateParams.folderIds.split('/');
    }
  }
}
Maksym
  • 458
  • 4
  • 23
  • @TheGreenFoxx how does your starter pack help to answer my question? – Maksym Jul 29 '16 at 11:38
  • Look at this http://stackoverflow.com/questions/25866387/angular-ui-router-programmatically-add-states – jofftiquez Jul 29 '16 at 12:07
  • Your link does not help, my question is not about creating states at runtime - i'ts about creating an endless hierarchy of states in the config. – Maksym Jul 29 '16 at 12:39
  • are all the *no actual limit* hierachy states gonna be nested all the way? that would be lots of nested states! If not, I do think you had quite a good (clever) solution by using the `split` function :P – CozyAzure Jul 29 '16 at 18:32
  • @CozyAzure, this endles hierarchy would be present on one of the screens of an app. In reality, it would rarely have more than, say, 10 or 15 levels – Maksym Jul 29 '16 at 19:20

0 Answers0