0π
β
I got the answer,
In my custom StringifyQuery, I mutate the query Object to add square brackets to it key (destinations[]: Hanoi)
And then after that, the router still use that object and show in the next route
That why, when I console.log this.$route.query
it shows the edited query (destinations[]: Hanoi)
To fix that, I have to avoid mutating the query object, and thatβs all
full code in CodeSandbox
stringifyQuery: (query) => {
const queryClone = { ...query };
Object.keys(queryClone).forEach((item) => {
if (
Array.isArray(queryClone[item]) &&
queryClone[item].length === 1 &&
!item.includes("[]")
) {
queryClone[`${item}[]`] = queryClone[item];
delete queryClone[item];
}
});
return qs.stringify(queryClone, {
encode: false,
indices: false,
arrayFormat: "comma",
addQueryPrefix: true,
});
},
My lesson: Never mess with an outside object, we have to clone it (deep or shadow base on context) and edit it in the clone version
Source:stackexchange.com