J
J
juan_chikatilo2022-03-31 19:47:33
Vue.js
juan_chikatilo, 2022-03-31 19:47:33

How to create a route group in vue-router?

Hello!
I can't figure out how to create a route group. I tried through children but it works through the parent router-view i.e. not through the very first router-view, but descends from parent to child, etc., as I understand it.

I need this to set one meta per route group.
those. I want so:

{
        path:"/admin",
        name: 'Admin',
        meta:{isAdmin:true},
        component: () => import('./views/admin/Main.vue'),
        children:[
            {
                path:'user',
                name:'allUsers',
                component: () => import('./views/admin/User/allUsers.vue'),
            },
            {
                path:'products',
                name:'allProducts',
                component: () => import('./views/admin/Products/allProducts.vue'),
            },
        ]
    },


To not write like this all the time
{
        path:"/admin",
        name: 'Admin',
        meta:{isAdmin:true},
        component: () => import('./views/admin/Main.vue'),
},
{
         path:'/admin/user',
         name:'allUsers',
meta:{isAdmin:true},
         component: () => import('./views/admin/User/allUsers.vue'),
},
{
         path:'/admin/products',
         name:'allProducts',
meta:{isAdmin:true},
         component: () => import('./views/admin/Products/allProducts.vue'),
},


Or will you still have to add meta to all routes?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question