[英]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.