简体   繁体   English

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

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

I am trying to implement react-admin in my project however upon render I get this message我正在尝试在我的项目中实现 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.

There is very little to be found about this issue and I'm not entirely sure how to go about setting the history.关于这个问题几乎没有发现,我不完全确定如何设置历史记录。 I've tried importing createHistory from 'history/createHashHistory' but then I get this error我尝试从“history/createHashHistory”导入 createHistory,但随后出现此错误

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

Is there a way to get this rendering properly?有没有办法正确地得到这个渲染? And if so, what would be the proper way to go about configuring the Admin Component's history?如果是这样,go 关于配置管理组件历史的正确方法是什么?

index.js 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')
);

AdminPage.js管理页面.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;

App.js应用程序.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;

The proper way to write a reducer in this case is documented at https://marmelab.com/react-admin/CustomApp.html#using-an-existing-redux-provider .在这种情况下编写减速器的正确方法记录在https://marmelab.com/react-admin/CustomApp.html#using-an-existing-redux-provider中。

But from what I see, you don't need one.但据我所知,你不需要一个。 You just added the thunk middleware, which is useless in react-admin as it already handles sagas.您刚刚添加了 thunk 中间件,它在 react-admin 中没有用,因为它已经处理了 sagas。

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

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