先在组件里用一个守卫:
/** * 路由守卫 */ beforeRouteEnter(to, from, next) { next(vm => { vm.canGoBack = from.name ? true : false; }); },
然后就可以判断 canGoBack:
if (this.canGoBack) { this.$router.back(); } else { this.$router.push('/'); }