简体   繁体   中英

How to pass link to react ant design model “Confirm/yes/ok ” click button

Here my problem is when I click the button to show this model. I need to pass the link when I click the model button "ok" this link go to..how do I do?

图片

Here is my button code:

   <Button onClick={this.showConfirm} style={{ color: '#036cd2',verticalAlign:'middle', borderColor: '#ffffff', backgroundColor: '#ffffff', border: 0, visibility: this.props.colBtn,marginRight:5 }}  shape={'circle'}><Icon type="poweroff" /></Button>

this my model function:

  showConfirm=() =>{
      confirm({
        title: 'Do You Want to Logout...?',

        onOk() {
          console.log('Ok');
        },
        onCancel() {
          console.log('Cancel');
        },
      });
    }

Here is my logout function:

 logout(){
        var accessToken =localStorage.getItem('access_token');
        if(!accessToken){
            axios.post(`${Config.serverUrl}/api/Employes/logout?access_token=${accessToken}`, null).then((response) =>{
                localStorage.clear();
            });
        }else {
            message.error('access token required ');
        }

    }

this coding working without a model. I need(with model) when I click "ok" button link and logout function must work.

  { <Link  to="/user-login"  ><Button onClick={this.logout} style={{ color: '#036cd2',verticalAlign:'middle', borderColor: '#ffffff', backgroundColor: '#ffffff', border: 0, visibility: this.props.colBtn,marginRight:5 }}  shape={'circle'}><Icon type="poweroff" /></Button></Link> }

You dont have to add a Link there. You can simply call your logout() inside onOk .

showConfirm=() =>{
      confirm({
        title: 'Do You Want to Logout...?',

        onOk() {
          logout();
        },
        onCancel() {
          console.log('Cancel');
        },
      });
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM