如何传递与URL到UI的SREF数据? [英] How can I pass data with URLs to ui-sref?

查看:180
本文介绍了如何传递与URL到UI的SREF数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为纽约我有:<一个UI的SREF =app.file({路径:file.path})> {{file.path}}< / A>

file.path HTML /英雄sidebar.html

我的状态定义为:

  .state('app.file', {
    url: '/file/*path'
    views:
      repositoryView:
        templateUrl: '/templates/app/_file.html'
  })

但是,当我点击链接,它进入的http://本地主机:9001 /应用程序/文件/ HTML%252Fhero-sidebar.html

我要的是它去的http://本地主机:9001 /应用程序/文件/ HTML /英雄sidebar.html

这可能使用的UI路由器AngularJS?

Is this possible using ui-router with AngularJS?

推荐答案

UI路由器Github上 ,你可以发现它的 这里

为了解决这一点,你需要添加你的配置这里面code将采取URL的编码和解码的照顾。

In order to solve this you need to add this code inside your config which will take care of encoding and decoding of url.

您可以覆盖内置的字符串类型(这是执行
  斜线编码),使用下面code注册自己更换字符串类型

you could override the built-in string type (which is performing the slash encoding) by registering your own replacement "string" type using below code

code

app.config(['$urlMatcherFactory', '$stateProvider', function($urlMatcherFactory, $stateProvider) {
    //$stateProvider.state() & other code here

    function valToString(val) {
        return val != null ? val.toString() : val;
    }

    function regexpMatches(val) { /*jshint validthis:true */
        return this.pattern.test(val);
    }
    $urlMatcherFactory.type("string", {
        encode: valToString,
        decode: valToString,
        is: regexpMatches,
        pattern: /[^/]*/
    });
}]);

工作Plunkr

这篇关于如何传递与URL到UI的SREF数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆