简体   繁体   English

React组件在浏览器后退/前进按钮上中断

[英]React component breaks on browser back/forward button

I have two forms, one is called profile, the other is settings. 我有两种形式,一种叫做配置文件,另一种是设置。 I'm using introjs to have a guided tour through these two forms. 我正在使用Introjs对这两种形式进行导览。 If I only move forward through the tour using the introjs 'Next Step' button there are no issues (first image). 如果我仅使用introjs的“下一步”按钮前进到游览,就没有问题(第一张图片)。 But, if I use the browser back or forward button, my forms look like the second image. 但是,如果使用浏览器的“后退”或“前进”按钮,则表单看起来像第二张图像。 这是第一页

这是使用后退按钮后

Code on profile page that utilize introjs: 使用introjs的个人资料页面上的代码:

runTour() {
if (this.state.showTour === true) {
  const tourObj = {
    userId: Meteor.userId(),
    page: 'profile',
  };
  introJs.introJs().setOption('doneLabel', 'Next step').start().oncomplete(() 
=> {
    changeIntroTour.call(tourObj);
    browserHistory.push('/user/settings');
  })
    .onexit(() => {
      changeIntroTour.call(tourObj);
    });
 }
}

componentWillReceiveProps(nextProps) {
  this.existingSettings(nextProps);
  if (nextProps.intro.length > 0) {
    this.setState({
      showTour: nextProps.intro[0].profileTour,
    }, () => {
      this.runTour();
    });
  }
}

The issue was I was not calling introJs.exit() on componentWillUnmount. 问题是我没有在componentWillUnmount上调用introJs.exit()。 This was keeping my instance of introJs running from one component to the next which caused the bug. 这使我的introJ实例从一个组件运行到另一个组件,导致该错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检测反应 class 组件中的浏览器后退按钮 - How can I detect browser back button in react class component 如何区分浏览器后退/前进按钮? - How to distinguish browser back / forward button? 禁用地址栏和浏览器的前进和后退按钮 - disable address bar and back and forward button of browser JavaScript和浏览器的后退/前进按钮 - JavaScript and the browser's back/forward button 在禁用浏览器后退按钮的同时启用前进按钮 - Enable forward button while disabling browser back button 在 React 中,单击浏览器后退按钮时,我应该单击一个 DOM 元素(例如,按钮)并且应该在同一个组件中 - In React, On clicking browser back button I should click one DOM ele(for instance, button) and should be in the same component 如何通过单击angularjs中的浏览器后退/前进按钮来后退/转发用户的历史记录 - how to back/forward user 's history by clicking the browser back/forward button in angularjs 在浏览器中按后退或前进按钮时,URL会更改,但内容不会更改 - On back or forward button press in a browser the URL changes but the content does not 在带有框架的浏览器中返回按钮(前进的历史记录不起作用) - Button Back in Browser with Frames (history forward don't work) history.pushstate使浏览器后退和前进按钮失败 - history.pushstate fails browser back and forward button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM