Angular.js: ngRoute should support route params containing urlencoded slashes

Created on 16 Dec 2014  路  6Comments  路  Source: angular/angular.js

Request Type: feature

How to reproduce: http://plnkr.co/edit/cHsrkTifPonHRaCWSp7q?p=preview

Component(s): ngRoute

Impact: small

Complexity:

This issue is related to:

Detailed Description:

It seems that ngRoute does not support route params containing urlencoded slashes(%2F).

I'm working on an api mock service whose data is organized by paths(e.g. /repos/:owner/:repo/issues). The dashboard app for this service is built on Angular. The url for api /repos/:owner/:repo/issues was expected to be https://myservice.doamin/#/apis/%2Frepos%2F%3Aowner%2F%3Arepo%2Fissues and will be routed to /apis/:api. However ngRoute decoded the hash and replaced it with #/apis//repos/:owner/:repo/issues, which will be misrouted.
The plnkr above shows a simplified situation.

I searched through docs, stackoverflow and github issues, only finding one possible way to get around this problem by encoding the path twice and decode the $routeParams in controllers. That's unnatural.

Params containing urlencoded slashes are reasonable and should be supported(, rather than be rounded). So is there a possible way to do it, or am i missing something?

Other Comments:

ngRoute broken expected use bug

Most helpful comment

I too would like to see the router's behaviour implemented this way.
In my route params are URIs of resources and I was very surprised to find that the router doesn't match them as @leeyeh mentioned. This caused me some headaches, as it is not clear to me why this limitation exists.

Edit
I just noticed that $routeProvider.when() understands the star operator, which might may help here At least it worked for me. E.g. /resource/:uri*

All 6 comments

I'm experiencing exactly the same issue http://stackoverflow.com/q/27677688/1993501

@leeyeh @edi9999
As a work around, you can encodeURIComponent the string you want to include in the route twice, something like:

encodeURIComponent(encodeURIComponent( "this/path/is/just/a/parameter" ))

so ngRoute will decode it once, storing %2F in the right url parameter placeholder

I too would like to see the router's behaviour implemented this way.
In my route params are URIs of resources and I was very surprised to find that the router doesn't match them as @leeyeh mentioned. This caused me some headaches, as it is not clear to me why this limitation exists.

Edit
I just noticed that $routeProvider.when() understands the star operator, which might may help here At least it worked for me. E.g. /resource/:uri*

I got exactly same issue: the $routeParams decoded twice, so I have to encodeURIComponent to make it work.

Is this going to get some love?

This is still an issue. You need to encode the URI params twice for angular route to correctly perform the redirect or the template injection

Was this page helpful?
0 / 5 - 0 ratings