这是我与 ui-sref
属性指令一起使用的链接:
<a ui-ref="show.hastitle({uuid:item.uuid, title:item.title})">
标题参数可以是波斯语单词,我期望的是如下链接:
http://domain.com/page/54c82de2978af/ه-فف٢٠
但是ui-sref
返回如下:
http://domain.com/page/54c82de2978af/%D9%88%D8%A7%DA%98%D9%87-%D9%81%D8%A7%D8%B1%D8% B3%DB%8C
我使用过如下解决方案:
var noneEncodedUri = {
encode: function(str) { return str && str.replace(/ /g, "-"); },
decode: function(str) { return str && str.replace(/-/g, " "); },
is: angular.isString,
pattern: /[^/]+/
};
$urlMatcherFactoryProvider.type('noneEncodedUri', noneEncodedUri);
$stateProvider.state('mystate', {
url: "/{title:noneEncodedUri}"
})
但是渲染的链接没有改变
如何完全停止 ui-sref
编码 url 参数?
最佳答案
我使用此作用域函数来解决我的问题:
$scope.beautyUri = function (uuid, title) {
return decodeURIComponent($state.href("show.hastitle", {uuid: uuid, title: title}));
};
并在 html 中使用此函数,如下所示:
<a href="{{beautyUri(item.uuid, item.title)}}">{{title}}</a>
关于javascript - 如何停止 ui-sref 编码 url 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32867026/