1. 使用vue-router的replace方法:
this.$router.replace('/newRoute')
  1. 使用window.location.replace方法:
window.location.replace('/newRoute')
  1. 使用history.replaceState方法:
history.replaceState(null, '', '/newRoute')

注意:使用第二种和第三种方法会刷新页面,而第一种方法不会。

vue和js替换当前路由的几种方式

原文地址: https://www.cveoy.top/t/topic/gjBx 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录