使用 react admin 设置 redux 提供程序

问题描述

我想将我的项目包装在一个 redux 商店中。我不想在 react admin 中使用它,只在我项目的其余部分中使用它。

我只是在我的 src/index.js 文件中使用通常的 redux 提供程序代码

ReactDOM.render(
    <Provider store={store}>
        <Router>
            <App />
        </Router>,</Provider>,document.getElementById("root")
);

这是给我这个错误

Error: Missing history prop.
When integrating react-admin inside an existing redux Provider,you must provide the same 'history' prop to the <Admin> as the one used to bootstrap your routerMiddleware.
react-admin uses this history for its own ConnectedRouter.

我看过他们关于 Including React-Admin In Another Redux Application 的部分,但我觉得这对我来说可能太多了?首先,我在今天之前从未听说过 redux-saga,其次,我不需要从我的管理面板发送操作,所以我不确定我是否需要所有这些。

不过我可能错了。

有没有更简单的方法解决这个问题?谢谢!

解决方法

您可以将两个应用程序分开,每个应用程序都有自己的路由和 redux 提供程序。

ReactDOM.render(
    <Router>
        <Switch>
            <Route path="/admin" component={AdminApp} />
            <Route path="/" component={App} />
        <Switch>
    </Router>,document.getElementById("root")
);

然后在App组件中设置redux Provider。