Angular2向空查询参数添加true [英] Angular2 adds true to empty query parameters

查看:63
本文介绍了Angular2向空查询参数添加true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

导航到这样的网址时:

/some/url;page=1;q=

该网址会自动更改为:

/some/url;page=1;q=true

是否可以禁用此功能,以便我可以使用一个空参数?

Is it possible to disable this so that i could have an empty parameter?

推荐答案

我在我的应用程序中遇到了同样的问题,到目前为止,唯一对我有用的方法是完全删除空的url参数.因此,如果这是网址

I've been having the same issue in my application and so far, the only thing that has worked for me is removing the empty url parameter entirely. So if this is the url

/some/url;page=1;q=

在检查url参数时,如果为q === '',则可以使用delete()从对象中删除q来获取

when you check the url params, if q === '', you can remove q from the object with delete() to get this

/some/url;page=1

我知道这不是最好的解决方案,我很想找到一个不涉及在我的代码中检查空url参数的修补程序.

I understand this is not the best solution, I would love to find a fix that does not involving checking for empty url parameters all over my code.

我也理解将q=保留在URL中的好处,即使该参数为空,我仍未找到实现此目的的方法.

I also understand the benefit of keeping q= in the url, even if the parameter is empty, I have just not found a way to do that yet.

这篇关于Angular2向空查询参数添加true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆