angular 路由跳转 参数也能拿到 走了constructor但是没执行 ngOinit

现在是这样 扫码打卡 打卡成功图标亮起 点击点亮图标可跳转路由
路由 通过复制链接确实变了 但是上一个路由的元素仍然显示是什么鬼
就是路由组件的元素 重叠在一起了现在在当前
但是 如果刷新 再点击跳转就没问题
前一个路由

发现 constructor中获取参数是走了的 但是没有走 ngOnInit

  openPassModal(stage_id) {
    console.log('过关关卡:' + stage_id);
    if (this.userStage.all_pass && this.userStage.all_pass.received_at == 0) {
      this.isPassAllVisible = !this.isPassAllVisible;
    } else {
      console.log('跳转奖品码' + stage_id);
      this.router.navigate([`/page/prizeCode`], {
        queryParams: {
          id: stage_id
        }
      })
    }
  }

当前路由


  ngOnInit() {
    this.getUserStage();
  }

  getUserStage() {
    this.api.userStage.detail({}).subscribe(res => {
      this.userStage = res;
      this.userStage.first_win && this.userStage.first_win.winning_at != 0 && this.userStage.first_win.received_at == 0 && this.id ? this.getFirstPrize() : '';
      this.userStage.all_pass && this.userStage.all_pass.winning_at != 0 && this.userStage.all_pass.received_at == 0 && !this.id ? this.getAllPrize() : '';
    })
  }

当前路由也能获取到传参 就是渲染重叠了 不知道为什么
求大神指教

阅读 2.6k
2 个回答

用了路由复用了吗?这个功能有很多毛病。

要不然就是某些绑定的变量取值是undefined造成。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进