AngularJS路由中如何匹配可选路由和未确定路由?

How to match optional and undetermined routes in AngularJS routing?

在AngularJS路由中,我知道星号(*)可以匹配带斜杠的路径,问号(?)可以匹配可选路径,但是如何组合呢?我想将 /admin/tasks/admin/tasks/arbitrary/path/with/slashes 匹配在一起。

我试过这个:

    $routeProvider.when('/admin/tasks/:path*?', {
        templateUrl: './templates/admin/task.html',
        controller: 'AdminTaskController'
    })

可以匹配/admin/tasks//admin/tasks/arbitrary/path/with/slashes,但不能匹配/admin/tasks。这很奇怪,因为 doc 说:

Route path (matched against $location.path). If $location.path contains redundant trailing slash or is missing one, the route will still match and the $location.path will be updated to add or drop the trailing slash to exactly match the route definition.

为什么路由不能匹配没有结尾斜杠的 URL?

此外,在文档中,

path can contain optional named groups with a question mark: e.g.:name?.

但实际上单独使用 ? 无法匹配带斜杠的路径。

我通过复制解决了它。这并不理想,但它有效:

.when('/system/:path?',{
    templateUrl:'assets/templates/pages/system.html',
    controller: "SystemController",
    controllerAs: "systemCtrl"
})
.when('/system/:path*',{
    templateUrl:'assets/templates/pages/system.html',
    controller: "SystemController",
    controllerAs: "systemCtrl"
});

现在当人们输入 http://localhost/system/files/15/delete 它会识别它,如果他们只是转到 http://localhost/system