1
與自述的例子工作在反應路由器,終極版的歷史不被接受(從示例代碼)
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
),並且一切按預期工作。