In my router there is a dynamic Route that I need to set the last part of its path after the data is fetched from the store call in beforeRouteEnter
beforeRouteEnter (to, from, next) {
if(to.params.categoryId) {
next(vm => {
store.dispatch('getSearchResults', to.params)
.then(res => {
let category = res.data.categories.find(cat => cat.id == to.params.categoryId);
to.params.CName = category.name;
// to.path = to.path + `/${category.name}`;
console.log(to)
}).catch(err => false)
})
}else next();
the Route:
{
path: 'directory/bc-:categoryId(\\d+)?/:CName?',
name: 'SearchResults',
component: () => import(/* webpackChunkName: "listing" */ '../views/SearchResults.vue')
},
I need to change the CName in the Route to category.name from the data so that the route finally shows the category name after the Id
You should use a route with 2 children - one that will dispatch the Vuex action and then go to the other child.