路徑引數(裡面沒有編碼的斜槓)

預設情況下,ui-router 對引數中的斜槓/進行編碼。如果要在 URL 中傳送路徑,則需要定義自定義引數型別。

限定:

module.config(['$urlMatcherFactoryProvider', function($urlMatcherFactory) {
  $urlMatcherFactory.type('path', {
    decode: function(val) { return val != null ? val.toString() : val; },
    encode: function(val) { return val != null ? val.toString() : val; },
    is: function(val) { return this.pattern.test(val); },
    pattern: /[^/]+\/[^/]+/
  })
}]);

並使用:

$stateProvider.state({
  url: '/my-route/{directory:path}'
  template: '<my-page></my-page>'
});

相關問題