Answer the question
In order to leave comments, you need to log in
How to form routes with asynchronous data?
I have a router.js file in which I set routes, for example, Main and Category:
import Vue from 'vue'
import VueRouter from 'vue-router'
const routes = [
{
path: '/',
name: 'Main',
component: () => import('./views/Main.vue'),
},
{
path: '/category',
name: 'Category',
component: () => import('./views/Category.vue'),
}
]
export function createRouter() {
const router = new VueRouter({
scrollBehavior() {
return { x: 0, y: 0 }
},
mode: 'history',
routes
})
router.beforeEach((to, from, next) => {
document.title = to.meta.title
next()
})
return router
}
store.dispatch('categories')
path: '/(cat1|cat2|cat3)/
Answer the question
In order to leave comments, you need to log in
Use dynamic routing and process the received ID - https://router.vuejs.org/en/guide/essentials/dynam...
const routes = [
{
path: '/',
name: 'Main',
component: () => import('./views/Main.vue'),
},
{
path: '/category',
name: 'Category',
component: () => import('./views/Category.vue'),
},
{
path: '/:category',
// ...
}
]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question