AngularJS包罗万象的路线? [英] AngularJS catch-all route?
问题描述
我工作在AngularJS文件编辑软件。我的网址是这样的:
#/ fileName.md
块引用>或
#/文件夹/ fileName.md
块引用>或
#/文件夹/嵌套文件夹/另一个文件夹/ itgoesonforever / filename.MD
块引用>我不希望有对每一个做深度的路线,它可能是〜15条航线深。有什么方法让有条件的路线?粗制滥造:
/:fileorfolder /?fileorfolder /?fileorfolder /?fileorfolder?
解决方案我觉得你可以用角做的最好的是
*
,这是新的一样的的 $的 routeProvider V1.1.5:
路径
可以包含开头的明星命名组(*名称
)。所有字符都急切地存储在$ routeParams
当路由匹配以给定名字。结果
例如,路线像/颜色/:彩色/大code / *大code /修改
将匹配/彩色/褐色/大code / code /带/斜线/编辑
和提取:结果
-颜色:棕色
结果
-大code:code /带/斜杠
块引用>您不得不解析
大code
参数虽然自己I'm working on a file editing application in AngularJS. My urls look like this:
#/fileName.md
or
#/folder/fileName.md
or
#/folder/nested-folder/another-folder/itgoesonforever/filename.MD
I don't want to have to do a route for every single depth and it could be ~15 routes deep. Are there any ways to have conditional routes? Crudely:
/:fileorfolder?/:fileorfolder?/:fileorfolder?/:fileorfolder?
解决方案I think the best you can do with Angular is
*
, which is new as of v1.1.5 of $routeProvider:
path
can contain named groups starting with a star (*name
). All characters are eagerly stored in$routeParams
under the given name when the route matches.
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
You'd have to parse the
largecode
param yourself though.这篇关于AngularJS包罗万象的路线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!