如何在角路线通配符 [英] how to have wildcards in angular routes

查看:124
本文介绍了如何在角路线通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆