【问题标题】:Setting up redux provider with react admin使用 react admin 设置 redux 提供程序
【发布时间】:2021-08-20 15:58:09
【问题描述】:

我想将我的项目包装在 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,其次,我不需要从管理面板调度操作,所以我不确定我是否需要所有这些。

我可能错了。

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

【问题讨论】:

    标签: javascript reactjs redux react-admin


    【解决方案1】:

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

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

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

    【讨论】:

    • &lt;Switch&gt; &lt;Route path="/admin" component={AdminApp} /&gt; &lt;Route path="/" component={App} /&gt; &lt;/Switch&gt; 成功了,谢谢!
    • 菜鸟失误……好接球!
    猜你喜欢
    • 1970-01-01
    • 2021-12-04
    • 1970-01-01
    • 2011-07-22
    • 2020-11-20
    • 2011-03-28
    • 2021-04-11
    • 1970-01-01
    • 2016-07-07
    相关资源
    最近更新 更多