如果导航重回(<)将用户退出MYB页面,该如何使用Vuerouter设置后备路径/路线?

发布于 2025-02-12 14:13:08 字数 660 浏览 1 评论 0原文

我对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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文