【问题标题】:how to stop ui-sref encoding url params如何停止 ui-sref 编码 url 参数
【发布时间】:2015-09-30 13:10:41
【问题描述】:

这是我与ui-sref 属性指令一起使用的链接:

<a ui-ref="show.hastitle({uuid:item.uuid, title:item.title})">

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 参数?

【问题讨论】:

标签: javascript angularjs angularjs-directive angular-ui-router


【解决方案1】:

我已经使用这个范围函数来解决我的问题:

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

【讨论】:

  • 最好使用ng-href
【解决方案2】:

我遇到了这个问题,但是经过很多不成功的搜索,找到解决方案其实很简单 你可以在 $scope.item.title 上使用 javaScript decodeURIComponent() 函数,对我来说它就像魅力一样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-29
    • 2017-07-12
    • 2016-09-15
    • 1970-01-01
    相关资源
    最近更新 更多