【发布时间】:2016-03-20 17:09:35
【问题描述】:
使用 React Router 有没有一种方法可以在不使用 mixin 的情况下使用确认离开路由?我们使用的是 es6 类,不能使用 mixin。
这就是我想要完成的: https://github.com/rackt/react-router/blob/latest/docs/guides/advanced/ConfirmingNavigation.md
【问题讨论】:
标签: reactjs react-router
使用 React Router 有没有一种方法可以在不使用 mixin 的情况下使用确认离开路由?我们使用的是 es6 类,不能使用 mixin。
这就是我想要完成的: https://github.com/rackt/react-router/blob/latest/docs/guides/advanced/ConfirmingNavigation.md
【问题讨论】:
标签: reactjs react-router
您将需要使用History 模块,然后使用listenBefore():
history.listenBefore(function (location) {
if (input.value !== '') {
return 'Are you sure you want to leave this page?'
}
})
查看Confirming Navigation 文档。
【讨论】:
this.unlisten = browserHistory.listenBefore(function() { if (!window.confirm('Leaving?')) { return false; } }); this.unlisten();