任何人都可以帮我弄清楚如何让这个设置正常工作。
import 'babel-polyfill';
import React from 'react';
import ReactDOM from "react-dom";
import {Provider} from 'react-redux';
import {createStore, applyMiddleware} from 'redux';
import thunk from 'redux-thunk';
import promise from 'redux-promise';
import createLogger from 'redux-logger';
import allReducers from './reducers';
import App from './components/App';
import createHistory from 'history/createBrowserHistory'
import { Route } from 'react-router-dom'
import { ConnectedRouter, routerMiddleware, push } from 'react-router-redux'
const logger = createLogger();
// Create a history of your choosing (we're using a browser history in this case)
const history = createHistory()
// Build the middleware for intercepting and dispatching navigation actions
const middleware = routerMiddleware(history)
// Add the reducer to your store on the `router` key
// Also apply our middleware for navigating
const store = createStore(
allReducers,
applyMiddleware(middleware, thunk, promise, logger)
)
ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history}>
<div>
<Route exact path="/" component={App}/>
</div>
</ConnectedRouter>
</Provider>,
document.getElementById('root')
);
我似乎收到了一个错误。警告:React.createElement:type无效 - 期望一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:undefined。您可能忘记从其定义的文件中导出组件。
答案 0 :(得分:1)
确保Components
层次结构中的所有App
都已正确导出为默认导出。
另请查看从react-router
Components
开始的地方。尝试从Link
模块导入react-router
组件时常见错误,但它仅存在于react-router-dom
模块中。
答案 1 :(得分:1)
感谢所有反馈,答案是ConnectedRouter未定义。我现在已正确修复此导入。