vue-router install 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
/*

*/

//route.js - We need to craate file under src
import linkName from './components/fileName.vue';
export const routes = [
  {
    path: '/',
    component: linkName
  }
]

Example 2: install vue js

npm install -g vue-cli    //make sure you have node and npm installed 
vue init webpack   //  eg:  vue init webpack myapp
cd                // cd myapp
npm install
npm run dev  //server will start in port 8080

Tags:

Misc Example