vue install router code example
Example 1: install vue router
npm install vue-router
Example 2: installing vue router & implementation
npm install vue-router
import VueRouter from 'vue-router';
Vue.use(VueRouter);
const router = new VueRouter({
routes,
mode: 'history'
});
new Vue({
router,
render: h => h(App)
}).$mount('#app')
import linkName from './components/fileName.vue';
export const routes = [
{
path: '/',
component: linkName
}
]
Example 3: install vue router
cd [project]
npm install --save vue-router
Example 4: setup vue router
import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
Example 5: vue router implementation
import VueRouter from 'vue-router';
Vue.use(VueRouter);
const router = new VueRouter({
routes,
mode: 'history'
});
new Vue({
router,
render: h => h(App)
}).$mount('#app')
import linkName from './components/fileName.vue';
export const routes = [
{
path: '/',
component: linkName
}
]
Example 6: router configuration vue
npm install --save vue-router
Vue.use(VueRouter):
const routes=[
{path: '/home', component: [componentName]},
{path: '/features', component: [componentName2]},
.
.
.
];
const router=new VueRouter({
routes,
mode: 'history'
});
new Vue({
router, <----
.
.
}).$mount('#app')
<template>
<div id="app">
<Navbar></Navbar>
<router-view> </router-view> <----------
<Footer></Footer>
</div>
</template>