取消最后一个重定向reactjs react-router

时间:2018-08-08 14:59:24

标签: javascript reactjs react-router

我有一个reactjs应用程序,在某些组件中,当componentWillUnmount时,我必须显示一条确认消息。想法是用户不确认退出,我必须取消当前的重定向。

这是我有的

  componentWillUnmount() {
     const { dispatch } = this.props;
     const confirmationMessage = 'you are leaving the page, are you sure?';
     const retVal = confirm(confirmationMessage);
     if (!retVal) {
        dispatch(redirect(current_url));
     }
   }

不执行重定向的想法只是取消最后的重定向,并避免组件卸载。有什么主意吗?

0 个答案:

没有答案