admin管理员组文章数量:1323348
I wonder if this is possible - I need to match the following URLs with one pattern:
/one/app/home
/one/two/app/home
/one/two/three/app/home
...
I understand that AngularJS routing doesn't support regex, but Angular UI Router does.
main.config(function($stateProvider, $urlRouterProvider, $locationProvider) {
$urlRouterProvider.otherwise("/fail");
$stateProvider
.state("home", {
url: "{.+}/app/home",
templateUrl: "assets/tpl/home.html",
controller: "homeController"
})
$locationProvider.html5Mode(true);
});
This doesn't work though (goes to /fail
with all the examples). Is what I want to do possible at all?
I wonder if this is possible - I need to match the following URLs with one pattern:
/one/app/home
/one/two/app/home
/one/two/three/app/home
...
I understand that AngularJS routing doesn't support regex, but Angular UI Router does.
main.config(function($stateProvider, $urlRouterProvider, $locationProvider) {
$urlRouterProvider.otherwise("/fail");
$stateProvider
.state("home", {
url: "{.+}/app/home",
templateUrl: "assets/tpl/home.html",
controller: "homeController"
})
$locationProvider.html5Mode(true);
});
This doesn't work though (goes to /fail
with all the examples). Is what I want to do possible at all?
-
Use
.+
instead of{.+}
, and add a$
at the end to ensure theapp/home
part is the last one:.+/app/home$
– Robin Commented Apr 17, 2014 at 11:34 - @Robin I think there are certain limitations of URL parsing here not allowing this to work. – Caballero Commented Apr 17, 2014 at 11:38
-
Sorry, I wasn't familiar with Angular UI regex syntax... As a random thought I'd say it doesn't work either because the "name" part is mandatory (
{id:...}
), or because the regex can't include a/
(ie it's only applied between to slashes). But I'm not familiar with the specifics, so this is just a guess in the wild. Good luck! – Robin Commented Apr 17, 2014 at 11:45
1 Answer
Reset to default 6You should use it like this:
state("home", {
url: "/{beginPath:.+}{endPath:/app/home}",
templateUrl: "assets/tpl/home.html",
controller: "homeController"
});
Then you you will have access to $stateParams.beginPath
(which is equal to evertyhing before /app/home/
) and to $stateParams.endPath
which will be equal to /app/home/
If /one/
is necessary in the beggining then use something like this:
url: "/{beginPath:one/.+}{endPath:/app/home}"
本文标签: javascriptAngularJS Ui Router regex matching wildcard in urlStack Overflow
版权声明:本文标题:javascript - AngularJS Ui Router regex matching wildcard in url - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742132713a2422234.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论