vue router(按需加载)

./router/index.js

import Vue from "vue";
import Router from "vue-router";
// 普通的加载路由
import Home from "../views/Home.vue";
// 按需(懒)加载(vue实现)
// const Home = () => import(/* webpackChunkName: "home" */ '../views/home')

Vue.use(Router);

export default new Router({
  routes: [
    {
      path: "/",
      name: "home",
      component: Home
    },
    {
      path: "/about",
      name: "about",
      // route level code-splitting
      // this generates a separate chunk (about.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      // 路由级 代码拆分
	  // 这将为此路由生成一个单独的块(about.[hash].js)。
	  // 当路由被访问时,它被延迟加载。
      component: () =>
        import(/* webpackChunkName: "about" */ "../views/About.vue")
    }
  ]
});
posted @ 2019-06-24 18:14  未来的羁绊  阅读(1001)  评论(0编辑  收藏  举报