繁体   English   中英

反应管理员 | 未捕获的错误:缺少历史道具

[英]React Admin | Uncaught Error: Missing history prop

我正在尝试在我的项目中实现 react-admin 但是在渲染时我收到了这条消息

Uncaught 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.

关于这个问题几乎没有发现,我不完全确定如何设置历史记录。 我尝试从“history/createHashHistory”导入 createHistory,但随后出现此错误

Uncaught Could not find router reducer in state tree, it must be mounted under "router"

有没有办法正确地得到这个渲染? 如果是这样,go 关于配置管理组件历史的正确方法是什么?

index.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import { createStore, compose, applyMiddleware} from 'redux';
import { Provider } from 'react-redux';
import thunk from 'redux-thunk';
import { BrowserRouter as Router } from 'react-router-dom';
import { reducer } from './redux/reducer';
import * as serviceWorker from './serviceWorker';

const store = createStore(reducer, compose(
  applyMiddleware(thunk),
  window.navigator.userAgent.includes('Chrome') ?
  window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() : compose,
  ),
);

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

管理页面.js

import { Admin, Resource } from 'react-admin';
import jsonServerProvider from 'ra-data-json-server';

const dataProvider = jsonServerProvider('http://localhost:3000');

const AdminPage = () => {

  return (
    <Admin dataProvider={dataProvider}>
      <Resource name="services" />
    </Admin>
  )
}

export default AdminPage;

应用程序.js

import React from 'react';
import './App.css';
import AdminPage from './components/AdminPage';
import { Switch, Route } from 'react-router-dom';

const App = () => {

  return (
    <div className="app">
      <Switch>
        <Route exact path='/manage' component={ AdminPage } />
      </Switch>
    </div>
  );
}

export default App;

在这种情况下编写减速器的正确方法记录在https://marmelab.com/react-admin/CustomApp.html#using-an-existing-redux-provider中。

但据我所知,你不需要一个。 您刚刚添加了 thunk 中间件,它在 react-admin 中没有用,因为它已经处理了 sagas。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM