import Vue from "vue";
import VueRouter from "vue-router";
// import Home from "../views/Home.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Home",
    redirect: "/goods"
  },
  {
    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.
    component: () => import(/* webpackChunkName: "about" */ "../views/About.vue")
  },
  {
    path: "/goods",
    name: "Goods",
    component: () => import(/* webpackChunkName: "goods" */ "../views/Goods/index.vue")
  },
  {
    path: "/goods/detail",
    name: "GoodsDetail",
    component: () => import(/* webpackChunkName: "goodsDetail" */ "../views/Goods/detail.vue")
  },
  {
    path: "/goods/plan",
    name: "GoodsPlan",
    component: () => import(/* webpackChunkName: "GoodsPlan" */ "../views/Goods/plan.vue")
  },
  {
    path: "/goods/inform",
    name: "GoodsInform",
    component: () => import(/* webpackChunkName: "GoodsInform" */ "../views/Goods/inform.vue")
  },
  {
    path: "/user",
    name: "User",
    component: () => import("../views/User/index.vue")
  },
  {
    path: "/policy",
    name: "Policy",
    component: () => import("../views/Policy/index.vue")
  },
  {
    path: "/policy/detail",
    name: "Detail",
    component: () => import("../views/Policy/Detail/index.vue")
  },
  {
    path: "/introduction",
    name: "Introduction",
    component: () => import("../views/Introduction/index.vue")
  }
];

const originalPush = VueRouter.prototype.push;

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
  scrollBehavior() {
    return { x: 0, y: 0 };
  }
});

export default router;
