dynamic route in vuejs code example
Example 1: vue router link dynamic id
<div class="category-list" v-for="category in categories">
<router-link :to="{ name: 'category/edit', params: { categoryId: category.id }}">Home</router-link>
</div>
Example 2: url params vue
//we can configure the routes to receive data via the url
//first configure the route so it can receive data:
const routes=[
.
.
{path : '/page/:id?', name='page', component: Page},
.
.
//inside the Page component we can get the data:
name:'Page',
mounted(){
this.url_data=this.$route.params.id;
},
data(){
return{
url_data: null
};
}
//the data can be then used in the template section of the component
<h2> {{url_data}}</h2>