mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-04 21:18:01 +08:00
46 lines
1.0 KiB
Markdown
46 lines
1.0 KiB
Markdown
---
|
||
order: 8
|
||
title:
|
||
zh-CN: 销毁确认对话框
|
||
en-US: destroy confirmation modal dialog
|
||
---
|
||
|
||
## zh-CN
|
||
|
||
使用 `Modal.destroyAll()` 可以销毁弹出的确认窗。通常用于路由监听当中,处理路由前进、后退不能销毁确认对话框的问题。
|
||
|
||
## en-US
|
||
|
||
`Modal.destroyAll()` could destroy all confirmation modal dialogs. Usually, you can use it in router change event to destroy confirm modal dialog automatically
|
||
|
||
```jsx
|
||
import { Modal, Button } from 'antd';
|
||
import { browserHistory } from 'react-router';
|
||
|
||
// router change
|
||
browserHistory.listen(() => {
|
||
Modal.destroyAll();
|
||
});
|
||
|
||
const confirm = Modal.confirm;
|
||
|
||
function showConfirm() {
|
||
confirm({
|
||
title: 'confirm dialog',
|
||
content: 'click the browser [go back] button,this confirm modal dialog will destroy Automatically',
|
||
onOk() {
|
||
console.log('OK');
|
||
},
|
||
onCancel() {
|
||
console.log('Cancel');
|
||
},
|
||
});
|
||
}
|
||
|
||
ReactDOM.render(
|
||
<div>
|
||
<Button onClick={showConfirm}>Confirm</Button>
|
||
</div>, mountNode
|
||
);
|
||
```
|