如果导航重回(<)将用户退出MYB页面,该如何使用Vuerouter设置后备路径/路线?
我对Vue和Vue-Router非常新。目前,我正在研究一个我们组织网球比赛的页面,我的组件称为 gooback ,它基本上检查了您的浏览器历史记录条目,并带您回到上一个,类似于Back-箭头中的箭头。因此,我有这种行为,我不喜欢,我不知道如何更改它=>如果我设置了匹配项,请传递您的URL,如果您输入并单击我的GOBACK COMP,它将带您离开我的页面。我想避免使用这种逻辑,如果您的最后一个浏览器历史记录条目不在我的页面内,我想将您重定向到我的家。 这是GOBACK组件代码:
setup(props, { attrs }) {
const router = useRouter()
const { t } = useI18n()
const goBack = (): void => {
if (attrs.onClick) return
if (router.options.history.state.back === null) {
router.replace('/')
} else {
router.back()
}
}
return {
t,
goBack
}
}
})
</script>
谢谢!
I'm quite new with Vue, and vue-router. Right now I'm working on a page where we organize tennis matches, I have this component called goBack, it basically checks your browser history entries and take you back to the previous one, similar to the back-arrow in your browser. So I have this behavior which I don't like, and I don't know how to change it => if I set match, pass you the URL, if you enter and click on my goBack Comp it will take you out of my page. I want to avoid that with this logic, if your last browser history entry is not inside my page I want to redirect you to my home.
Here's the goBack component code:
setup(props, { attrs }) {
const router = useRouter()
const { t } = useI18n()
const goBack = (): void => {
if (attrs.onClick) return
if (router.options.history.state.back === null) {
router.replace('/')
} else {
router.back()
}
}
return {
t,
goBack
}
}
})
</script>
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论