我的路由器看起来像这样:
.state('project',{ 'url': '/project/*path','controller': 'ProjectController','templateUrl': '/pages/project.html',});
但是当我用的时候@H_404_4@
ui-sref="project({path: mypath})"
with mypath = part1 / part2我希望它变成/ project / part1 / part2但是我得到/ project / part1%2Fpart2.@H_404_4@
如何在不编码的情况下传递参数?@H_404_4@
因为它是
described here,所以你需要为URL参数声明自定义变量类型,以便不对斜杠进行编码.引用github的评论:
原文链接:https://www.f2er.com/angularjs/142298.htmlIf you really don’t want the slash encoded for you,register a custom type with your regexp and declare item_id to be your custom type,i.e.,url: /{item_id:MyType}@H_404_4@
function valToString(val) { return val != null ? val.toString() : val; } function valFromString(val) { return val != null ? val.toString() : val; } function regexpMatches(val) { /*jshint validthis:true */ return this.pattern.test(val); } $urlMatcherFactory.type("MyType",{ encode: valToString,decode: valFromString,is: regexpMatches,pattern: /[^/]+\/[^/]+/ });