Search code examples
javascriptvue.jsrouterlink

With vue.js, how can I set up a dynamic router-link with embedded children?


My router.js has some embedded children:

routes: [{
            path: '/',
            name: 'login',
            component: Login,
        },
        {
            path: '/app',
            component: Container,
            children: [{
                path: '',
                name: 'ConversationsList',
                component: ConversationsList
            }, {
                path: 'call',
                name: 'Call',
                component: Call
            }, {
                path: 'conversation/:id',
                name: 'ConversationDetail',
                component: ConversationDetail,
                children: [{
                    path: '',
                    name: 'ConversationDetailHighlights',
                    component: ConversationDetailHighlights

                }, {
                    path: 'transcript',
                    name: 'ConversationDetailFullTranscript',
                    component: ConversationDetailFullTranscript

                }]
            }]

        },
    ],

My current route is /app/conversation/:id and I want my template to have a link to /app/conversation/:id/transcript. How do I accomplish this with vue.js?


Solution

  • If I understood the question correctly, this should do:

    <router-link
      :to="{
        name: 'ConversationDetailFullTranscript',
        params: {
          id: 'some-id'
        }
      }">
      View full transcript
    </router-link>