router.beforeEach((to, from) => {
const route = this.$router.resolve(to)
if (route.resolved.matched.length) {
// the route exists, return true to proceed with the navigation
return true
}else{
//the route does not exists, prompt for confirmation
return confirm("Are you sure you want to leave this site?")
}
})
2条答案
按热度按时间vh0rcniy1#
您可以使用全局导航保护来检查用户是否正在导航到已识别的路线,并在导航离开之前提示确认。
类似于:
6qftjkof2#
结果证明,解决方案在Vue/VueRouter之外:
现在,浏览器不会记录特定于Vue的导航,单击“后退”箭头将显示浏览器的内置消息。