Setup: vue 2.6.14 & vue-router, my router config:
{
mode: 'history',
base: document.location.pathname,
routes: [
{
path: '/',
name: 'main',
component: Main,
props: (route) => {
return {
id: route.query.id,
};
},
pathToRegexpOptions: {
strict: true,
},
},
],
}
Problem: I have urls like this
local.host/page/xxx_111.html?id=111
The router base is /page/xxx_111.html path. At some point I would like to change the url via programmatic navigation to just
local.host/page/xxx_111.html
in other words, to get rid of query params, but whatever I do, I always get
local.host/page/xxx_111.html/
with trailing slash :( How to solve this?
Solved by making router's path: '/*([\\w\\-]+_?[\\d]+.html)' which matches any url of type local.host/<ANYTHING>/xxx_111.html and calls like this.$router.push({ query: {} }) to get rid of url param w/o adding trailing slash to the url.