如何调整角度的URL匹配模式 [英] How to Adjust Angular's URL matching pattern

查看:190
本文介绍了如何调整角度的URL匹配模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先第一件事情,我想调整的角度用来匹配的URL路由模式。我发现的功能和它运行的是URL位置对这些正则表达式(S)上angular.js 5612行发现(版本的 HTTP://$c$c.angularjs.org/1.1.5/ ):

First things first, I want to adjust the pattern that Angular uses to match against for URL routing. I have found the function and it is running the URL location against these regex(s) found on line 5612 of angular.js (version http://code.angularjs.org/1.1.5/):

SERVER_MATCH = /^([^:]+):\/\/(\w+:{0,1}\w*@)?(\{?[\w\.-]*\}?)(:([0-9]+))?(\/[^\?#]*)?(\?([^#]*))?(#(.*))?$/,
PATH_MATCH = /^([^\?#]*)(\?([^#]*))?(#(.*))?$/,
DEFAULT_PORTS = {'http': 80, 'https': 443, 'ftp': 21};

那么,为什么我要这么做?我使用的角度作为一个桌面AIR应用程序的框架。 AIR应用程序可以使用HTML / JS,随后包裹在空气中,可以访问文件系统和操作系统来构建。因此,这样的组合基本上可以让你建立一个多平台的桌面Web应用程序与棱角分明。强大的东西。

So why would I want to do that? I am using angular as the framework for a desktop AIR application. AIR applications can be built using HTML/JS, which is subsequently wrapped in AIR which provides access to the filesystem and OS. So this combination essentially allows you to build a multi-platform desktop web application with angular. Powerful stuff.

这是问题所在AIR有一个自定义地址栏字符串,它看起来像应用程序:/ ,而不是的http:// 。因此它具有一个斜线,而不是两个。角使用地址栏的位置路由的应用程序,如 http://something.com/#/contactList 表示加载 contactList 视图及其相关的控制器。我的正则表达式的知识是pretty的(非常)有限的,所以我无法读取我包括上面的图案,但我猜测,一个斜杠,而不是两个或类似的东西可能是问题。

Here is the problem AIR has a custom address bar string which looks like app:/ rather than http://. So it has one slash instead of two. Angular uses the the address bar location to route the application, i.e. http://something.com/#/contactList means load the contactList view and its associated controller. My knowledge of regex is pretty (very) limited so I can't read the patterns I included above, but I am guessing that the one slash instead of two or something similar to that could be the problem.

我的目的是为了调整模式,以便应用程序:/ 将是一个有效的模式,我的希望是,URI段制造和相关的行动将仍然有效。

My aim is to adjust the patterns so that app:/ would be a valid pattern and my hope is that the URI segment making and associated actions would still work.

推荐答案

请参阅Mozilla的普通防爆pressions DOC:的https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Ex$p$pssions

See Mozilla Regular Expressions doc: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

什么@shaunhusain已经在注释中解释说主要是正确的,但以下情况除外:

What @shaunhusain already explained in a comment is mostly correct, except for the following:

  • \ W 匹配单个字母数字字符或下划线
  • + 匹配1个或多个(不为0或1)previous字符
  • \w matches a single alphanumeric character or underscore
  • + matches 1 or more (not 0 or 1) of the previous character

因此​​, \ w + 匹配长度为1个或多个字符的话。

Therefore, \w+ matches a word of length 1 or more characters.

您确实需要修改正则表达式只有冒号后的一个斜线,如果你想匹配类似应用程序:/

You do need to modify the regex to only have one slash after the colon if you want to match something like app:/.

这篇关于如何调整角度的URL匹配模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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