1

I am using angularjs 1.2.10,ngRoute and the default html5 mode of false. Using the follow url example:

http://example.com/#/route?message=test+message

In Chrome,firefox, and IE9 I am noticing the following parameter conversion:

?message=test+message - > ?messagetest%2Bmessage  

I am logging the nextLocation & currentRoute,nextRoute in the $locationChangeStart/$locationChangeSuccess & $routeChangeStart/$routeChangeSuccess event handlers respectively and I am seeing the following output:

locationChangeStart: http://example.com/#/route?message=test+message
locationChangeSuccess: http://example.com/#/route?message=test%2Bmessage
routeChangeStart: currentRoute: /route, nextRoute: /route
routeChangeSuccess: currentRoute: /route, nextRoute: /route
...
locationChangeStart: http://example.com/#/route?message=test%2Bmessage
locationChangeSuccess: http://example.com/#/route?message=test%2Bmessage
routeChangeStart: currentRoute: /route, nextRoute: /route
routeChangeSuccess: currentRoute: /route, nextRoute: /route

The route and its associated controller is getting instantiated twice which is undesirable. Is there a way to prevent this double instantiation or rewrite of '+' to %2B.

A similar behavior occurs when the parameter value has a space. In Chrome,IE9, the following conversion occurs:

?message=test message - > ?message=test%20message

However, this rewrite(and subsequent double route load) does NOT happen in firefox, which leads me to believe this is a browser specific behavior.

I don't have direct control of how the parameters are formed, an iframe in our site is doing a redirect to the 'top' location 'http://example.com/#/route' along with the parameters it adds.

mjj1409
  • 3,075
  • 6
  • 28
  • 28
  • I faced similar kind of issue too. Hope this solution i gave will help you [Special Characters in routeparams](http://stackoverflow.com/questions/18538620/special-characters-in-routeparams-angularjs) – Sai Feb 20 '14 at 15:42
  • @Sai Thanks for the link. It appears my situation is a little different, in that an iframe redirect to window.top is the trigger for the location change. I'm not sure if I can intercept this location change and 'fix' the special characters accordingly before the angular $digest. I've tried to do this in the events $locationChangeStart and $routeChangeStart with no success. – mjj1409 Feb 20 '14 at 21:07
  • What do you mean you don't have control over parameters formed? iframe cannot access parent URL. [access parent url from iframe](http://stackoverflow.com/questions/3420004/access-parent-url-from-iframe) – Sai Feb 21 '14 at 01:04
  • @Sai I believe javascript code in the iframe runs something like window.top.location.href="parent_url_redirect" see http://stackoverflow.com/questions/580669/redirect-parent-window-from-an-iframe-action-using-javascript – mjj1409 Feb 21 '14 at 12:41

0 Answers0