Aurelia: URL encoding/escaping frontslashes in route parameters

We wish to encode the parameters we use in our routes so that any frontslashes in the parameters are escaped and not interpreted as part of the path. How/where would we do that?

Say we have configured the following route with

route: ['foo/:bar']

If we have bar=“emperor/penguin” we want the resolved route to be ‘foo/emperor%2Fpenguin’ rather than ‘foo/emperor/penguin’, because the extra slash in the latter will lead to a non-existent page.

Side note:
If we have bar=“emperor penguin”, the space will be encoded, resulting in the route ‘foo/emperor%20penguin’. Why would spaces be encoded and not frontslashes?


The space being encoded but not the forward slash suggests it might be something to do with the difference between encodeURI and encodeURIComponent.


If it’s done automatically, it suggests to me that Aurelia is using encodeURI which may be a bug (or a design choice). You might want to clarify on the aurelia forum.

For now, you could manually escape your param using encodeURIComponent


There’s an open issue registered for this very case.

I second Michaels suggestion to manually encode the parameters in question with encodeURIComponent.


I see.
I’m not sure if you can answer this in general, but what would be the most convenient place(s) to do the encoding? By most convenient I mean what would require the lowest amount of changes.