使用
中自述文件中的示例https://github.com/ReactTraining/react-router/tree/master/packages/react-router-redux
我在索引中创建了这个布局:
// attach the redux dev tools extension for Chrome
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
// apply router logic as middleware
const history = createHistory();
const router_mw = routerMiddleware(history);
// second arg to createStore is the inital redux store state
const store = createStore(
reducers,
initialState,
composeEnhancers(
applyMiddleware(
ReduxPromise,
ReduxThunk,
router_mw
)
));
// --> add routes for logs, opsec, etc. later
ReactDOM.render(
<Provider store={ store }>
<ConnectedRouter history={ history }> // <- error here
<div>
<Route exact path="/" component={ LoginScreen } />
<Route path="/comp1" component={ comp1 } />
<Route path="/comp2" component={ comp2 } />
</div>
</ConnectedRouter>
</Provider>
, document.getElementById('root')
);
任何编译它的尝试都会抱怨ConnectedRouter入口点中的{history}:
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. Check your code at index.js:52.
我错过了什么?这是react-router-redux
改造 - 返回react-router
(并将ConnectedRouter
更改为BrowserRouter
),一切正常。
答案 0 :(得分:0)
我使用react-router-dom@4.2.2
并遇到同样的问题,直到将react-router-redux
更新为^5.0.0-alpha.9
。
如果您使用react-router-dom@4
,则应使用react-router-redux@5
,react-router-redux repo中说明了这一点:
react-router-redux的下一个版本将是5.0.0,并将与react-router 4.x兼容。目前正在积极开发over there。随意帮忙!