使用带斜杠的变量的路由提供者

use routeprovider with variable with slashes

我已经定义了这个 url,/item/1231,但是可以使用带有斜线的变量作为 itemID 吗?

如果我的商品 ID 是 12/31,这怎么行?是否必须编码为 %2F?

/item/12/31

  $routeProvider.when('/item/:itemID', {
    templateUrl: 'item_view.html',
    controller: 'ItemControler'

来自文档:

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.

path can contain named groups starting with a colon: e.g. :name. All characters up to the next slash are matched and stored in $routeParams under the given name when the route matches. path can contain named groups starting with a colon and ending with a star: e.g.:name*. All characters are eagerly stored in $routeParams under the given name when the route matches. path can contain optional named groups with a question mark: e.g.:name?.

For example, routes like /color/:color/largecode/:largecode*/edit will match /color/brown/largecode/code/with/slashes/edit and extract:

color: brown

largecode: code/with/slashes.

https://docs.angularjs.org/api/ngRoute/provider/$routeProvider

但我还没成功

好吧,正如文档所说,只需要添加 and * 即可忽略斜杠。

 $routeProvider.when('/item/:itemID*', {
    templateUrl: 'item_view.html',
    controller: 'ItemControler'