如何在角路线通配符 [英] how to have wildcards in angular routes
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/12685085/angularjs-route-how-to-match-star-as-a-path\">AngularJS - 干线 - 如何匹配星号(*)为路径
如何在我的路线指定通配符 -
How do I specify wildcards in my routes -
$routeProvider
.when('/admin/*', {
templateUrl: 'admin.html',
controller: 'AdminCtrl'
})
所以上面应该/管理/用户/管理/用户的工作/ 1 /管理/组织/ 3。所以有可能是一个或管理员后路径的两个层次。我该怎么做 ?
So the above should work for /admin/users and /admin/users/1 or /admin/org/3. So there could be either one or two levels of path after admin. How do I do it ?
推荐答案
目前AngularJS不支持在定期航线前pression。
Currently AngularJS does not support regular expression in routes.
您可以解决方法如下:
app.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/admin', {templateUrl: 'admin.html', controller: 'AdminCtrl'})
.when('/admin/:type', {templateUrl: 'admin.html', controller: 'AdminCtrl'})
.when('/admin/:type/:id', {templateUrl: 'admin.html', controller: 'AdminCtrl'});
}]);
<一个href=\"http://plnkr.co/edit/tBumW2oEqki2sEl1hjSc?p=$p$pview\">http://plnkr.co/edit/tBumW2oEqki2sEl1hjSc?p=$p$pview
IMO,这是好主意,为管理员和用户独立的控制器,除非否则,你有一些特殊的要求。
IMO, it is good idea to have the separate controller for both admin and users, unless otherwise you have some special requirement.
这篇关于如何在角路线通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!