AngularJS - 路线 - 如何匹配星(*)作为路径 [英] AngularJS - Route - How to match star (*) as a path

查看:24
本文介绍了AngularJS - 路线 - 如何匹配星(*)作为路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作资源查看器应用程序,但问题是我试图匹配 when("/!/:resourceUrl").

I'm making a resource viewer app, but the problem is that i tried to match when("/!/:resourceUrl").

如果资源 url 类似于 /path,它可以正常工作,但我怎样才能制作类似于 /path/to/the/resource 的东西.
不知道要走多少路,所以不能.when("/!/:path1/:path2/:path3").

It works fine if the resource url is something like /path, but how can I make something like a /path/to/the/resource.
I don't know how much paths will it take, so I can't do .when("/!/:path1/:path2/:path3").

有什么想法吗?

推荐答案

从 angular-1.2 开始,您可以这样做:

As of angular-1.2 you can do this:

when("/!/:resourceUrl*")

http://code.angularjs.org/1.2.0/docs/api/ngRoute.$routeProvider

特别是文档给出了以下示例:

In particular the documentation gives the following example:

例如,像 /color/:color/largecode/:largecode*/edit 这样的路由将匹配 /color/brown/largecode/code/with/slashs/edit 并提取:

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

  • 颜色:棕色
  • 大码:code/with/slashs

这篇关于AngularJS - 路线 - 如何匹配星(*)作为路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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