2017-07-07 129 views
3

是否有方便的方法取消所有路由變更的使用axios,redux-thunk,redux?我知道axios有取消令牌,應將其添加到每個請求中,我可以撥打source.cancel(/* message */)來取消它。取消路由變更請求(React/Redux/Axios)

P.S.目前我在componentWillUnmount處理這個。也許有更好的?

回答

0

我發現的最簡單的方法是將source存儲在狀態中,如果請求正在發送,則使用source.cancel

componentWillUnmount() { if(isLoading) { source.cancel() } }

+0

但是他們說,裏面存儲功能店不好idea.Store應該serializable.You可以讀到這個[這裏](https://redux.js.org/docs/faq/OrganizingState .html#can-i-put-functions-promises-or-other-non-serializable-items-in-my-store-state)。我也在尋找解決方案。 –