角JS'路线'不匹配%2F组件(EN codeD'/') [英] Angular JS 'route' doesn't match component with %2F (encoded '/')
问题描述
我有角的JS'路线'如下:
I have a 'route' in Angular JS as follows
$routeProvider.when('/foos/:fooId', { controller: FooController, templateUrl: 'foo.html'});
和它的伟大工程,除非:fooId组件包含一个/或%2F(EN codeD格式)
and it works great, unless the :fooId component contains either a '/' or '%2F' (encoded form)
我怎样才能使这项工作,我的'fooId可以包含/秒?
How can I make this work, my 'fooId' can contain /s ?
推荐答案
您不能很容易地做到这一点,因为如果你在使用它与%2F
A环节,浏览器将只去code为你,它会最终被 /
。 AngularJS目前不允许你在 $路线
PARAMS使用 /
。
You can't easily do this because if you use a link with %2F
in it, the browser will just decode it for you and it'll end up being /
. AngularJS currently doesn't allow you to use /
in $route
params.
您可以双击连接code它,就像在这个plnkr:<一href=\"http://plnkr.co/edit/e04UMNQWkLRtoVOfD9b9?p=$p$pview\">http://plnkr.co/edit/e04UMNQWkLRtoVOfD9b9?p=$p$pview
You can double encode it, like in this plnkr: http://plnkr.co/edit/e04UMNQWkLRtoVOfD9b9?p=preview
var app = angular.module('app', []);
app.controller('HomeCtrl', function ($scope, $route) {
});
app.controller('DirCtrl', function ($scope, $route) {
var p = $route.current.params;
$scope.path = decodeURIComponent(p.p1);
});
app.config(function ($routeProvider) {
$routeProvider
.when('/', {templateUrl: 'home.html', controller: 'HomeCtrl'})
.when('/dir/:p1', {templateUrl: 'dir.html', controller: 'DirCtrl'})
.otherwise({redirectTo: '/'});
});
和链接将是:&LT; A HREF =#/ DIR / A%252Fb%252Fc&gt;点击此处&lt; / A&GT;
另一种选择,如果你有 /
在参数字符可以在这里找到了一组数字:<一href=\"http://stackoverflow.com/questions/16600538/how-can-i-make-the-angular-js-route-the-long-path/16600968#16600968\">How我可以让angular.js路线长路径
Another option, if you have a set number of /
characters in your parameters can be found here: How can I make the angular.js route the long path
这篇关于角JS'路线'不匹配%2F组件(EN codeD'/')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!