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

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

问题描述

我正在尝试匹配1个参数,该参数可以具有2种值:当前"或具有至少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 ,但是当我重新加载页面时,它将恢复为 default .

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天全站免登陆