[Vuejs]-How can I get component depends on vue router param?

0👍

You can use the dynamic components and pass the id param as props to your route.
Something like:

const Category = Vue.component('category', {
  name: 'category',
  template: '#category',
  props: ['id']
});

const router = new VueRouter({
  routes: [
    { path: '/category/:id', name: 'category', component: Category, props: true },
  ]
})

and in template:

<template id="category">
  <div>
    <h3>Category : {{ id }}</h3>
    <component :is="id"></component>
  </div>
</template>

fiddle example

-1👍

Couldn´t you just make the component itself dynamicly change its content based on the route id?

Leave a comment