解决Vue中同一路由报错

路由跳转问题

在这里插入图片描述

Js处理版本

import VueRouter from 'vue-router';
const oldPush = VueRouter.prototype.push;
const oldReplace = VueRouter.prototype.replace;
VueRouter.prototype.push = function (location) {
    
    
  return oldPush.call(this, location).catch(err => err);
};
VueRouter.prototype.replace = function (location) {
    
    
  return oldReplace.call(this, location).catch(err => err);
};

Ts处理版本

import VueRouter, {
    
     RawLocation, Route } from 'vue-router';
const oldPush: (location: RawLocation) => Promise<Route> = VueRouter.prototype.push;
const oldReplace: (location: RawLocation) => Promise<Route> = VueRouter.prototype.replace;
VueRouter.prototype.push = function (location: RawLocation) {
    
    
  return oldPush.call(this, location).catch((err: any) => err);
};
VueRouter.prototype.replace = function (location: RawLocation) {
    
    
  return oldReplace.call(this, location).catch((err: any) => err);
};

猜你喜欢

转载自blog.csdn.net/qq_34191778/article/details/126167072