import Vue from "vue" import Router from "vue-router" Vue.use(Router) //登录 注册 激活 const page = [ { path: "/", redirect: "/questionnaire" //调试 }, // { // path: "/login", // meta: { index: 1, keepAlive: false }, // name: "login", // component: () => import("@/pages/login") // }, { path: `/feedback/:dataId`, meta: { index: 2, keepAlive: false }, name: "feedback", component: () => import("@/pages/feedback") }, { path: `/questionnaire`, meta: { index: 2, keepAlive: false }, name: "questionnaire", component: () => import("@/pages/questionnaire") } ] const router = new Router({ // scrollBehavior: () => ({ // y: 0 // }), routes: [...page] }) router.beforeEach((to, from, next) => { next() }) // 解决编程式路由往同一地址跳转时会报错的情况 const originalPush = Router.prototype.push const originalReplace = Router.prototype.replace // push Router.prototype.push = function push(location, onResolve, onReject) { if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject) return originalPush.call(this, location).catch((err) => err) } //replace Router.prototype.replace = function push(location, onResolve, onReject) { if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject) return originalReplace.call(this, location).catch((err) => err) } export default router