dojo / framework

Dojo Framework. A Progressive Framework for Modern Web Apps
https://dojo.io/
Other
580 stars 79 forks source link

Route config support wildcard #330

Closed xiaohulu closed 4 years ago

xiaohulu commented 5 years ago

Enhancement

Package Version: 5.0

I want design a REST API {owner}/{project}/tree/{branch}/* to view the folder structure.

|- root
    |- folder1
          |- folder2
                 |- folder3
                        |- file1
  1. use {owner}/{project}/tree/{branch} to get folder1
  2. use {owner}/{project}/tree/{branch}/folder1 to get folder2
  3. use {owner}/{project}/tree/{branch}/folder1/folder2 to get folder3

It is similar to github's repo url.

Code

I use router config like below first

{
    "path": "{owner}/{project}/tree/{branch}/{folderPathes}",
    "outlet": "view-project-tree"
}

folderPathes can be empty or null, 'folder1', 'folder1/folder2' which contains /

But the router can not switch '{owner}/{project}/tree/{branch}/folder1' to '{owner}/{project}/tree/{branch}/folder1/folder2'

may be here do a check

https://github.com/dojo/framework/blob/master/src/routing/Router.ts#L244

if (route.segments[segmentIndex] === undefined) {
    type = 'partial';
    break;
}

because route.segments length is greater than params length

So I expect to support wildcard like this

{
    "path": "{owner}/{project}/tree/{branch}/*",
    "outlet": "view-project-tree"
}

Expected behavior:

{
    "path": "tree/*",
    "outlet": "view-tree"
}

* can be zero or more segments

  1. if view the root folder, then the path is tree, not include the ending /
  2. if view the second level, then the path is tree/folder1
  3. if view the third level, then the path is tree/folder1/folder2
  4. ...
xiaohulu commented 5 years ago

May be, route config should be nested router.

{
    "path": "tree",
    "outlet": "view-tree-root",
    "children": [
        {
            "path": "*", 
            "outlet": "view-tree-children"
        }
    ]
}

which can partial refresh the tree part.