I am facing an issue with my router configuration. I have a dynamic Route that requires the last part of its path to be set after fetching data from a 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 current Route setup is as follows:
{
path: 'directory/bc-:categoryId(\\d+)?/:CName?',
name: 'SearchResults',
component: () => import(/* webpackChunkName: "listing" */ '../views/SearchResults.vue')
},
I need to update the CName parameter in the Route to reflect the category's name from the fetched data so that the final route displays the category name after the Id.