angularjs $位置服务和地址栏随routeParams中的+,空格而变化

时间:2014-02-20 15:34:47

标签: angularjs urlencode angularjs-routing

我正在使用angularjs 1.2.10,ngRoute和默认的html5模式false。 使用以下网址示例:

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

在Chrome,Firefox和IE9中,我注意到以下参数转换:

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

我正在记录nextLocation& currentRoute,nextRoute在$ locationChangeStart / $ locationChangeSuccess& $ routeChangeStart / $ routeChangeSuccess事件处理程序分别和我看到以下输出:

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

路由及其关联的控制器实例化两次,这是不可取的。有没有办法防止这种双重实例化或将'+'重写为%2B。

当参数值有空格时,会发生类似的行为。 在Chrome,IE9中,会发生以下转换:

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

但是,这个重写(以及后续的双路由加载)并不会在firefox中发生,这让我相信这是一种特定于浏览器的行为。

我无法直接控制参数的形成方式,我们网站中的iframe正在重定向到“顶部”位置“http://example.com/#/route”及其添加的参数。

0 个答案:

没有答案