質問

Is it possible to write a rule such as this:

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

Which matches each path contained in parenthesis optionally? So the above rule would match all of the following paths:

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

// And so on...
役に立ちましたか?

解決

I'm not sure if it's possible to specify routes in this way, but usually for this kind of route you'd just use search params, like /?q=rope&costMin=0&costMax=10 (I'm assuming this is a search operation). This way, the params are optional and it will still match the base path.

Just specify the route like this:

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

and then inject $routeParams into your controller and you can access the params:

$routeParams = { q: 'rope', costMin: '0', costMax: '10' }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top