reactjs – React-Router-Redux:在’react-router-redux’中找不到导出’syncHistoryWithStore’

前端之家收集整理的这篇文章主要介绍了reactjs – React-Router-Redux:在’react-router-redux’中找不到导出’syncHistoryWithStore’前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在尝试将Redux集成到我的应用程序中,并且遇到使用React-Router-Redux 5.0.0-alpha.6的问题

我收到错误:’react-router-redux’中找不到“export’syncHistoryWithStore’.官方指南说要导入syncHistoryWithStore,我已经完成了:
https://github.com/reactjs/react-router-redux

我也查看了react-router-redux包里面,似乎没有任何syncHistoryWithStore的迹象.

我错过了什么?

这是我的index.js. Redux正在工作,但我无法使用ConnectedRouter推送新路由,显然这是由于浏览器历史事物.

  1. import React from 'react';
  2. import { render } from 'react-dom'
  3. import { Provider } from 'react-redux';
  4. import { Route } from 'react-router'
  5. import { ConnectedRouter,routerReducer,routerMiddleware,syncHistoryWithStore,push } from 'react-router-redux'
  6. import createHistory from 'history/createBrowserHistory'
  7.  
  8. const store = configure();
  9. const history = syncHistoryWithStore(createBrowserHistory(),store);
  10.  
  11. const navigation = (
  12. <Provider store={store}>
  13. <ConnectedRouter history={history}>
  14. <SystemManager>
  15. <div>
  16. <Route path="/" component={Dashboard}/>
  17. <Route path="/dashboard" component={Dashboard} />
  18. .....
  19.  
  20. <Route component={NotFound} />
  21. </div>
  22. </SystemManager>
  23. </ConnectedRouter>
  24. </Provider>
  25. );
  26. injectTapEventPlugin();
  27.  
  28. render(navigation,document.getElementById('app'));

包装版本:

  1. react-redux: "^5.0.4",react-router: "^4.1.1",react-router-dom: "^4.1.1",react-router-redux: "^5.0.0-alpha.6",
对于遇到相同问题的任何人,我将发布我的工作index.js文件(注意:我已经离开了我的自定义组件和reducers以获得进一步的指导).

我现在不使用syncHistoryWithStore.我使用插件历史/ createBrowserHistory并为ConnectedRouter创建历史记录.到目前为止,一切似乎都在起作用..

我使用Redux DevTools并且还使用节点环境在dev和prod模式之间切换.

显然没有提供保修.

  1. import React from 'react'
  2. import ReactDOM from 'react-dom'
  3. import { createStore,combineReducers,applyMiddleware,compose } from 'redux'
  4. import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly';
  5.  
  6. import { Provider } from 'react-redux'
  7.  
  8. import createHistory from 'history/createBrowserHistory'
  9. import { Route,Switch } from 'react-router'
  10.  
  11. import { ConnectedRouter,routerMiddleware } from 'react-router-redux'
  12. import injectTapEventPlugin from 'react-tap-event-plugin';
  13.  
  14. import menu from './reducers/menu';
  15. import permissions from './reducers/permissions';
  16. import sitePreferences from './reducers/sitePreferences';
  17. import user from './reducers/user';
  18.  
  19.  
  20. // Custom Page Container Imports (these are the visual layout components)
  21. import SystemManager from './containers/systemManager/systemManager';
  22.  
  23. import LoginPage from './containers/pages/login-page/';
  24. import NotFound from './containers/pages/not-found/not-found';
  25.  
  26. // Create a history of your choosing (we're using a browser history in this case)
  27. const history = createHistory()
  28.  
  29. // Build the middleware for intercepting and dispatching navigation actions
  30. const middleware = routerMiddleware(history)
  31.  
  32. const isProduction = process.env.NODE_ENV === 'PRODUCTION';
  33.  
  34. // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  35. // Redux: Store creation and middleware application based on production/development mode
  36. // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
  37. let store = null;
  38.  
  39. if (isProduction === true) {
  40. store = createStore(
  41. combineReducers({
  42. menu,permissions,sitePreferences,user,routerReducer
  43. }),compose(applyMiddleware(middleware))
  44. );
  45.  
  46. } else {
  47.  
  48. store = createStore(
  49. combineReducers({
  50. menu,composeWithDevTools(applyMiddleware(middleware))
  51. );
  52.  
  53. }
  54. injectTapEventPlugin(); // Material UI
  55.  
  56. ReactDOM.render(
  57. <Provider store={store}>
  58. { /* ConnectedRouter will use the store from Provider automatically */ }
  59. <ConnectedRouter history={history}>
  60. <SystemManager>
  61. <Switch>
  62. <Route path="/dashboard" component={NotFound} />
  63. <Route path="/login" component={LoginPage} />
  64. </Switch>
  65. </ SystemManager>
  66.  
  67. </ConnectedRouter>
  68. </Provider>,document.getElementById('app')
  69. )

猜你在找的React相关文章