0

是否可以编写如下规则:

$routeProvider.when('(/CostMin/:costMin)?(/CostMax/:costMax)?(/Keywords/:keywords)?', {
    ...
});

哪个可选匹配括号中包含的每个路径?因此,上述规则将匹配以下所有路径:

/
/CostMin/0
/CostMin/0/CostMax/10
/CostMin/0/CostMax/10/Keywords/rope
/Keywords/rope

// And so on...
4

1 回答 1

2

我不确定是否可以以这种方式指定路线,但通常对于这种路线,您只需使用搜索参数,例如/?q=rope&costMin=0&costMax=10(我假设这是一个搜索操作)。这样,参数是可选的,它仍然会匹配基本路径。

只需像这样指定路线:

$routeProvider.when('/', { ... });

然后注入$routeParams您的控制器,您可以访问参数:

$routeParams = { q: 'rope', costMin: '0', costMax: '10' }
于 2014-02-10T11:55:11.023 回答