2

I am building a Vue 3 frontend and am using Vue Router 4 for navigation. I want to build a generic navigation based on the router definition. I want to use the current route and show links to the children of the route, but I see no children.

Here is what I do in my component:

<script setup>
import { useRoute } from 'vue-router';
import { onMounted } from 'vue';

const route = useRoute();

onMounted(async () => {
    console.error('route.children', route.children); // Shows undefined
});
</script>

Here is my route definition:

{
    path: '/users',
    name: 'users',
    component: usersComponent,
    meta: {
        title: 'Users'
    },
    children: [
        {
            path: 'images',
            name: 'userImages',
            component: imageComponent,
            meta: {
                title: 'Images'
            }
        },
        {
            path: 'profile',
            name: 'useProfile',
            component: profileComponent,
            meta: {
                title: 'Profile'
            }
        }
    ],
}
Darryl Noakes
  • 2,207
  • 1
  • 9
  • 27
Happo
  • 1,375
  • 3
  • 16
  • 34
  • Does this answer your question? [Can a component know its child-routes in vue-router](https://stackoverflow.com/questions/54578484/can-a-component-know-its-child-routes-in-vue-router) – Darryl Noakes Apr 25 '23 at 21:12
  • See also: [vuejs/vue-router#1149 - Expose child routes on currentRoute object](https://github.com/vuejs/vue-router/issues/1149) – Darryl Noakes Apr 25 '23 at 21:17

0 Answers0