Vue-router路由回退指定回退

tech2026-03-12  7

项目场景:

Vue-router路由回退/指定回退


问题描述:

Q: 不是应该用window.history.go(-1)吗? A: 不是的~

Q: 物理返回控制不了啊? A: 可以的~

Q: 666


解决方案:

路由回退

this.$router.go(-1);

指定回退

mounted() { //window.scrollTo(0, 0); if (window.history && window.history.pushState) { history.pushState(null, null, document.URL); window.addEventListener('popstate', this.keyBack, false); /* false阻止默认事件 */ } } destroyed() { window.removeEventListener('popstate', this.keyBack, false); /* false阻止默认事件 */ } methods: { keyBack() { return this.$router.push('/'); } }
最新回复(0)