vue router project code example
Example 1: installing vue router & implementation
//Installing Vue Router
npm install vue-router
//Implementation
//main.js - Add below lines
import VueRouter from 'vue-router';
Vue.use(VueRouter);
const router = new VueRouter({
routes,
mode: 'history'
});
new Vue({
router,
render: h => h(App)
}).$mount('#app')
//App.vue - Add below line in v-content
/*
<template>
<v-app>
<v-content>
<router-view></router-view>
</v-content>
</v-app>
</template>
*/
//route.js - We need to craate file under src
import linkName from './components/fileName.vue';
export const routes = [
{
path: '/',
component: linkName
}
]
Example 2: vue router implementation
//Implementation
//main.js - Add below lines
import VueRouter from 'vue-router';
Vue.use(VueRouter);
const router = new VueRouter({
routes,
mode: 'history'
});
new Vue({
router,
render: h => h(App)
}).$mount('#app')
//App.vue - Add below line in v-content
/*
<template>
<v-app>
<v-content>
<router-view></router-view>
</v-content>
</v-app>
</template>
*/
//route.js - We need to craate file under src
import linkName from './components/fileName.vue';
export const routes = [
{
path: '/',
component: linkName
}
]