AngularJS包罗万象的路线? [英] AngularJS catch-all route?

查看:122
本文介绍了AngularJS包罗万象的路线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作在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屋!

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