我在路由器的某处出现问题,这是错误消息React.createElement:类型无效-应该是字符串。
我写了有关此问题的每篇文章,但仍然没有解决。
我是React的初学者,我想开始一个新项目。
我的index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { AppContainer } from 'react-hot-loader';
import { BrowserRouter as Router, Route, IndexRoute } from 'react-router-dom';
import { Provider } from 'redux';
import createBrowserHistory from 'history/createBrowserHistory';
import App from './js/pages/App/App';
import Container from './js/components/Container/Container';
import store from './js/store';
const app = document.getElementById('app');
const newHistory = createBrowserHistory();
ReactDOM.render((
<Provider store={store}>
<Router history={newHistory}>
<Route path="/" component={App}>
<Route path="/container" component={Container} />
</Route>
</Router>
</Provider>
),
app
);
module.hot.accept();
我的store.js
import {applyMiddleware, createStore} from "redux";
import {createLogger} from "redux-logger";
import thunk from "redux-thunk";
import promise from "redux-promise-middleware";
import {save, load} from "redux-localstorage-simple";
import reducer from "./reducers/index";
var createStoreWithMiddleware = null;
if (process.env.NODE_ENV !== 'production') {
createStoreWithMiddleware
= applyMiddleware(
promise(),
thunk,
createLogger()
)(createStore);
}
else {
createStoreWithMiddleware
= applyMiddleware(
promise(),
thunk
)(createStore);
}
//const middleware = applyMiddleware(promise(), thunk, createLogger());
const store = createStoreWithMiddleware(
reducer // Loading done here
);
export default store;
我认为这是个问题,因为当我删除提供程序时,我会看到“应用程序”页面。
谢谢您的帮助。
答案 0 :(得分:0)
提供程序是React Redux提供的高阶组件,可让您将Redux绑定到React。
根据redux的文档: https://redux.js.org/advanced/usagewithreactrouter
您需要
import { Provider } from 'react-redux'