Reactjs 如何在redux传奇中导航路由器?

Reactjs 如何在redux传奇中导航路由器?,reactjs,react-router,jsx,redux-saga,react-router-redux,Reactjs,React Router,Jsx,Redux Saga,React Router Redux,版本:“反应路由器dom”:“^4.1.2”, “react router redux”:“^5.0.0-alpha.8” 我可以通过以下方式在我的组件中成功导航路由器: this.props.history.push(“/cart”) 然后我想在我的saga.js中导航路由器,我尝试了一些方法,但都不起作用: const history=createHistory(); 收益率呼叫(history.push,“/cart”) 屈服呼叫(put('/cart)//react路由器redux h

版本:“反应路由器dom”:“^4.1.2”, “react router redux”:“^5.0.0-alpha.8”

我可以通过以下方式在我的组件中成功导航路由器:

this.props.history.push(“/cart”)
然后我想在我的saga.js中导航路由器,我尝试了一些方法,但都不起作用:

const history=createHistory();
收益率呼叫(history.push,“/cart”)
屈服呼叫(put('/cart)//react路由器redux
history.push(“/cart”)
这些方法可以更改url,但页面不会呈现。 我添加了带有路由器的页面组件,但它也不起作用。 有人能帮我吗?谢谢

以下是我的一些设置:

const render=Component=>
ReactDOM.render(
,
document.getElementById('root'))
);
类应用程序扩展组件{
渲染(){
返回(
(
.....
)}/>
)
}
}
===============================================================

我通过这种方式解决了这个问题:用户路由器而不是BrosErrorOuter,然后

history.push(“/somerouter”)

您可以使用
react router redux
中的
push
方法。例如:

import { push } from "react-router-redux";

yield put(push('/')); /* inside saga generator function*/

您可以使用
react router
browserHistory

import { browserHistory } from "react-router";

yield browserHistory.push("/"); //put the path of the page you want to navigate to instead of "/"

我找到了一个简单的解决办法。 将组件内部的推送功能分派给saga

class App extends Component {
    foo = () => {
        const { dispatch } = this.props;

        dispatch({
            type: 'ADD_USER_REQUEST',
            push: this.props.history.push <<-- HERE
        });
    }

    render() { ... }
}

可能重复的是,我已经看到了这个问题,它不适合我,页面不会呈现页面仍然不会呈现
function* addUser(action) {
    try {
        yield put(action.push('/users'));

    } catch (e) {
        // code here...
    }
}