从Url中删除查询字符串参数。

时间:2021-08-17 13:02:25

Coming from AngularJS I thought this would be easy enough in Vue.js 2 as well. But it seems this is difficult by design in Vue.

来自AngularJS的我认为这在Vue足够简单。js 2。但从Vue的设计来看,这似乎很难实现。

In AngularJS I can do this $location.search('my_param', null); which will effectively turn https://mydomain.io/#/?my_param=872136 into https://mydomain.io/#/.

在AngularJS中,我可以执行这个$location。搜索(my_param,null);哪个将有效地转换https://mydomain.io/ ?my_param = 872136到https://mydomain.io/ /。

In Vue I have tried this.$router.replace('my_param',null);, but it will only do https://mydomain.io/#/?my_param=872136 -> https://mydomain.io/#/my_param, leaving the empty my_param.

在Vue中,我尝试过这个:$router.replace('my_param',null);,但是它只会做https://mydomain.io/ ?my_param = 872136 - > https://mydomain。io/#/my_param,留下空的my_param。

Isn´t there anyway in Vuejs2 to remove the query params from the Url? Should I resort to plain JS to achieve this?

反正不是´t Vuejs2删除查询参数的Url ?我应该使用普通的JS来实现这一点吗?

1 个解决方案

#1


2  

router.replace() is to navigate by removing the current URL from the browser history stack and replace it with the argument route you pass to it.

replace()是从浏览器历史堆栈中删除当前URL,并用传递给它的参数路由替换它。

The actual syntax is router.replace(url_location, onComplete, onAbort).

实际的语法是路由器。替换(url_location onComplete onAbort)。

What you are doing is router.replace(my_param, null) which is removing the current URL from the history stack and replacing it with 'my_param' and for the onComplete callback you are passing a null

你在做的是路由器。replace(my_param, null)将从历史堆栈中删除当前URL,并将其替换为'my_param',对于onComplete回调,您将传递一个null

So do it like this:

就像这样:

this.$router.replace('/')

More info on programatic navigation

更多关于程序导航的信息

#1


2  

router.replace() is to navigate by removing the current URL from the browser history stack and replace it with the argument route you pass to it.

replace()是从浏览器历史堆栈中删除当前URL,并用传递给它的参数路由替换它。

The actual syntax is router.replace(url_location, onComplete, onAbort).

实际的语法是路由器。替换(url_location onComplete onAbort)。

What you are doing is router.replace(my_param, null) which is removing the current URL from the history stack and replacing it with 'my_param' and for the onComplete callback you are passing a null

你在做的是路由器。replace(my_param, null)将从历史堆栈中删除当前URL,并将其替换为'my_param',对于onComplete回调,您将传递一个null

So do it like this:

就像这样:

this.$router.replace('/')

More info on programatic navigation

更多关于程序导航的信息