账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    vue.js 多router嵌套路由时如果带redirect参数无法传递
    51
    0

    1 router 环境
    两个router嵌套: bookRouter -> chapterRouter 对应URL为: /book/chapter
    其中chapterRouter配置了redirect, 到page0组件,url为 /book/chapter/page0

          path: '/chapter',
          redirect: 'chapter/page0',

    2 router client环境:
    在非上述router的页面, 如 /trial 页面,点击页面button试读,并传递参数 doc (是个js Object)

    this.$router.push({name: 'chapterRouter', params: {doc: this.doc}})

    3 运行问题
    在 bookRouter 、chapterRouter、Page0 组件的mounted 函数都尝试接受param, 但都收不到:

      mounted: function () {
        console.info('mounted')
        console.info(this.$route.params.doc)
      }

    4 正常情况.
    但是,如果chapterRouter没有设置redirect, bookRouter 和 chapterRouter mounted 都能收到 doc object参数

    0
    打赏
    收藏
    点击回答
        全部回答
    • 0
    • 对你没興趣 普通会员 1楼

      在Vue.js中,你可以使用history.push方法来重定向到一个不同的路由。如果你在多路由嵌套路由中使用redirect参数,但是它无法传递,那么可能是因为你在代码中没有正确地处理这个参数。

      以下是一个例子:

      javascript router.push({ path: '/section/:id', component: SectionComponent, name: 'Section', redirect: '/section/:id' });

      在这个例子中,/section/:id是目标路由的路径,Component: SectionComponent是目标路由的组件,name: 'Section'是目标路由的名称,redirect: '/section/:id'redirect参数的值,:id:id的参数。

      如果你在使用redirect参数时遇到问题,你可能需要检查你的代码,确保你正确地处理了这个参数,并且它的值在正确的位置。

    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部