Home > Software engineering >  where is the definition of router in import router from "./router"
where is the definition of router in import router from "./router"

Time:10-13

Reference: Bulma

https://github.com/troymott/bulma-book-code/blob/master/vuejs/src/main.js
import Vue from "vue";
import App from "./App.vue";
import router from "./router";

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

https://github.com/troymott/bulma-book-code/blob/master/vuejs/src/router/index.js

import Vue from "vue";
import Router from "vue-router";
...
import CustomerEdit from "../pages/CustomerEdit.vue";

Vue.use(Router);

export default new Router({
  routes: [{
      path: "/",
      redirect: '/login'
    },
...
  ],
  linkActiveClass: 'is-active' /* change to Bulmas active nav link */
});

Question> I am not able to find where the code defines the variable of router. May someone help point to me where the variable of router is defined within router/index.js?

Thank you

CodePudding user response:

It's not a variable or a function but an instance thats being passed from the router/index.js

export default new Router({
  routes: [{
      path: "/",
      redirect: '/login'
    },
...
  ],
  linkActiveClass: 'is-active' /* change to Bulmas active nav link */
});

is actually referenced by the variable router in main.js which is then used while creating the vue instance.

new Vue({
  el: "#app",
  router, // place of usage
  render: h => h(App),
});
  • Related