角有$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