angularjs ui 路由器正则表达式 [英] angularjs ui router regex

查看:37
本文介绍了angularjs ui 路由器正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试匹配可以有 2 种值的 1 个参数:当前"或至少包含 10 个密码的数字.

I'm trying to match 1 paramater that can have 2 kinds of values: 'current' or a number with at least 10 cyphers.

我试过了:

    url: '/history/{code:^current$|^[0-9]{10,}$}'

当我使用这个正则表达式时,我让我的应用程序转到 history/current,但是当我重新加载页面时,它返回到默认.

When I use this regexp I get my app to go to history/current, but when I reload the page it goes back to the default.

谁能帮忙说一下我做错了什么或者我该如何调试?

Can anyone help by saying what am I doing wrong or how could I debug that?

推荐答案

一个工作示例.状态定义为:

.state('history', { 
    //url: '/history/{code:^current$|^[0-9]{10,}$}',
    url: "/history/{code:current|[0-9]{10,}}",
    templateUrl: 'tpl.html',
})

这些链接应该符合我们的预期:

And these links should do what we expect:

Working:
<a href="#/history/current">history/current</a>
<a href="#/history/0123456789">history/0123456789</a>
<a href="#/history/1234567890123">history/1234567890123</a>

Will FAIL and fall to default:
<a href="#/history/other">history/other</a>
<a href="#/history/012345678">history/012345678</a> - 9 digits
<a href="#/history/123456789a">history/123456789a</a> - a at the end

此处

这篇关于angularjs ui 路由器正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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