1

In my app, I would like to match the url exactly. in case the url doesn't match exactly, I require to redirect to defualt as '`.

at present I require to test:

localhost:3000/sn=1234 or localhost:3000/sn=abc123 or localhost:3000/sn=abc123

that means, minimum the sn= should presence with values whether by number or alphabets or both mixed.

at present my state looks like this:

.state('serialCreateCase', {
        url: '^/sn={serialNumber}',
        templateUrl:'app/createCase/create-case.html',
        controller: 'createCaseController as ctrl'

      })

But it works for : both localhost:3000/sn=, localhost:300/sn - how to prevent this? and match the required value?

Thanks in advance.

4

1 回答 1

1

您可以对 state 参数使用正则表达式限定符。例如

url: '/sn={serialNumber:[a-z0-9]+}'

https://ui-router.github.io/docs/0.3.1/#/api/ui.router.util.type:UrlMatcher

注意:我删除了^您在 URL 上的前缀。我见过的任何文档都没有支持这种格式。

于 2016-10-17T05:05:52.470 回答