【问题标题】:How to define the route to external link with query如何使用查询定义到外部链接的路由
【发布时间】:2021-11-18 00:23:37
【问题描述】:

我正在尝试使用 beforeEnter()path 的外部链接 with query string 定义路由,如下所示:

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    beforeEnter() {location.href = '/path='+this.$router.query.path},
    name: 'Home',
    component: Home3
  },

但是我遇到了一个错误“无法读取未定义的属性(读取 $route)”。

我应该如何使用查询将正确的定义写入外部链接?

【问题讨论】:

    标签: vue.js vue-router


    【解决方案1】:

    There are 3 params in beforeEnter

    你的代码应该是这样的:

    beforeEnter(to, from, next) {
      location.href = '/path=' + to.query.path
      next()
    }
    

    【讨论】:

    • 它运行良好!谢谢!
    • 刚刚编辑,记得调用next()解析路由。
    猜你喜欢
    • 2019-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-11
    • 2022-01-17
    • 2018-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多