所有删除查询字符串的尝试都失败。
// Initial state
this.$router.replace({
name: 'routeName',
query: {
param: 123
}
});
// Errors
this.$router.replace({ query: {}});
this.$router.replace({ query: undefined });
this.$router.replace({ query: null });
如何删除查询而没有任何错误?
Vue-路由器v3.1.5
发布于 2020-01-21 12:13:01
出于某种原因,router.replace()
& router.push()
需要一个非空对象作为查询。因此,rest所要做的就是从值中清除初始查询对象,例如:
let query = {
param: [1, 2, 3]
};
// Initial state
this.$router.push({
name: 'yourRouteName',
query: query
});
// clean your initial query object
query.param = [];
// Now replace it
this.$router.replace({
query: query
});
发布于 2021-10-06 04:09:26
Vue 3
这对我起了作用:
import { useRoute, useRouter } from 'vue-router'
// put this inside your setup() function:
const route = useRoute()
const router = useRouter()
if (route.query.username = 'test') {
// do stuff...
// clear the query
router.replace({ query: {} })
}
发布于 2020-01-28 04:04:13
试试下面的代码:
let query = Object.assign({}, this.$route.query);
delete query.param;
this.$router.replace({ query });
https://stackoverflow.com/questions/59840396
复制相似问题