gpt4 book ai didi

reactjs - 使用 redux 中间件控制 react 路由器导航

转载 作者:行者123 更新时间:2023-12-04 13:57:26 26 4
gpt4 key购买 nike

在 Redux 中间件功能的帮助下,当 显示警告模式时离开播放页面 .

问题是我此时无法控制导航。在模态显示之前页面已更改。

有什么办法可以阻止路由器导航并根据模式选择做出决定?

enter image description here

middleware.push(routeIntrerceptor);

.....

const routeIntrerceptor = ({dispatch, getState}) => next => action => {
const state = getState();
const location = state.router.location.pathname;

if (action.type === '@@router/LOCATION_CHANGE' && location.includes('play')) {
dispatch({ type: 'SET_DIALOG_TOGGLE' });
}
next(action);
};

export default routeIntrerceptor;

最佳答案

如果你想阻止用户离开页面,你可以使用 <Prompt />它带有反应路由器。

检查 react 路由器的文档 -

https://reacttraining.com/react-router/web/example/preventing-transitions

关于reactjs - 使用 redux 中间件控制 react 路由器导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59318685/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com