Skip to content

Route config support wildcard #330

Closed
@xiaohulu

Description

@xiaohulu

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. ...

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions