ant-design/components/modal/demo/confirm-router.md

45 lines
1.1 KiB
Markdown
Raw Normal View History

---
order: 8
title:
2019-05-07 14:57:32 +08:00
zh-CN: 销毁确认对话框
en-US: destroy confirmation modal dialog
---
## zh-CN
使用 `Modal.destroyAll()` 可以销毁弹出的确认窗。通常用于路由监听当中,处理路由前进、后退不能销毁确认对话框的问题。
## en-US
2019-04-19 22:06:38 +08:00
`Modal.destroyAll()` will 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';
2019-12-25 21:28:06 +08:00
import { ExclamationCircleOutlined } from '@ant-design/icons';
2018-12-23 18:40:11 +08:00
function destroyAll() {
Modal.destroyAll();
2018-12-23 18:40:11 +08:00
}
2019-06-19 19:09:08 +08:00
const { confirm } = Modal;
function showConfirm() {
2018-12-23 18:40:11 +08:00
for (let i = 0; i < 3; i += 1) {
setTimeout(() => {
confirm({
2019-12-25 21:28:06 +08:00
icon: <ExclamationCircleOutlined />,
2019-05-07 14:57:32 +08:00
content: <Button onClick={destroyAll}>Click to destroy all</Button>,
2018-12-23 18:40:11 +08:00
onOk() {
console.log('OK');
},
onCancel() {
console.log('Cancel');
},
});
}, i * 500);
}
}
2020-07-16 13:46:57 +08:00
ReactDOM.render(<Button onClick={showConfirm}>Confirm</Button>, mountNode);
```