角有$urlMatcherFactory and UrlMatchers。
Plunker:http://plnkr.co/edit/MdazdvpVKjZhNjI6ErAH?p=preview
angular.module('myApp',[]).run(['$urlMatcherFactory',
function($urlMatcherFactory) {
var sourceList= ['John', 'Paul', 'George', 'Ringo']
var names = sourceList.join('|');
var urlMatcher = $urlMatcherFactory.compile("/{source:(?:" + names + ")}/:id");
$stateProviderRef
.state('names', {
url: urlMatcher,
templateUrl: 'tpl.root.html',
controller: 'MyCtrl'
});
}
]);
參見:Discussion on ui-router's UrlMatcher。
使用EXEC:
網址: /家/ 1參數1 = TT
var urlMatcher = $urlMatcherFactory.compile("/home/:id?param1");
var matched = urlMatcher.exec($location.path(), $location.search());
你得到2 fields
:ID ==> 1和參數1 ==> tt
我看過這篇文章,但它不直接訪問'UrlMatcher'對象 – CodeArtist
apparantly,var urlMatcher = $ urlMatcherFactory.compile(「'/ user/{id}?q &r'"); var matched = urlMatcher.exec('/ user/bob',{ x:'1',q:'hello' });這是你的意思嗎? –
是的,我要去嘗試一下。 – CodeArtist