[Vuejs]-What's the easiest way to implement routes in vue.js?

4👍

You can use Vue router library. Here, components is the folder where vue components are added. The variable "path" refers to the url route.

This is a sample router file I created.

     import Vue from "vue";
     import Router from "vue-router";

     Vue.use(Router);

     export default new Router({
       routes: [
       {
          path: "/",
          component: () => import("@/components/Login"),    
       },
       {
          path: "/home",
          name : "home",
          component: () => import("@/components/Home"),   
       },
     ]
    });

Please refer this document : https://v2.vuejs.org/v2/guide/routing.html

Also, import your router file into app initialisation.

 import router from "./router";

 new Vue({
   router,
   render: h => h(App)
 }).$mount("#app");

Leave a comment