路由重复点击有报错解决
import Vue from "vue";
import Router from "vue-router";
const originalPush = Router.prototype.push;
Router.prototype.push = function push (location) {
return originalPush.call(this, location).catch(err => err)
}
Vue.use(Router);
router清除add添加的路由
经常用于换用户登录不刷新的情况
const createRouter = () =>
new Router({
mode: "history",
scrollBehavior: () => ({ x: 0, y: 0 }),
routes: constantRoutes,
});
const router: any = createRouter();
export function resetRouter() {
const newRouter: any = createRouter();
router.matcher = newRouter.matcher;
}
export default router;