如何在Vue.js中对相同路径、不同查询参数使用router.push [英] How to use router.push for same path, different query parameter in Vue.js

查看:67
本文介绍了如何在Vue.js中对相同路径、不同查询参数使用router.push的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前网址是

/?type=1

我想在这个页面上使用 router.push.

I want to use router.push on this page.

this.$router.push('/?type=2');

但这会导致 NavigationDuplicated 错误.

But this gives NavigationDuplicated error.

我不想使用类似的参数

/:type

推荐答案

那是因为它与您当前的路径没有区别.如果 type 的值不同,它不会给你 NavigationDuplicated 错误.您也可以像下面这样分开查询,以确保框架可以理解它:

That's because it's not different from your current path. If the value of type is different it won't give you NavigationDuplicated error. you can separate query like below too to make sure it will be understandable by the framework:

this.$router.push({
   path: '/',
   query: { type: 2 },
});

这篇关于如何在Vue.js中对相同路径、不同查询参数使用router.push的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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