import createHistory from 'history/createHashHistory';
来源:5-23 集成react-router

qq_没有美腿的宝马_0
2019-04-09
import createHistory from ‘history/createHashHistory’;
官方文档没有你的操作步骤的
import React from 'react’
import ReactDOM from 'react-dom’
import { createStore, combineReducers } from 'redux’
import { Provider } from 'react-redux’
import { Router, Route, browserHistory } from 'react-router’
import { syncHistoryWithStore, routerReducer } from ‘react-router-redux’
import reducers from ‘/reducers’
// Add the reducer to your store on the routing
key
const store = createStore(
combineReducers({
…reducers,
routing: routerReducer
})
)
// Create an enhanced history that syncs navigation events with the store
const history = syncHistoryWithStore(browserHistory, store)
ReactDOM.render(
{ /* Tell the Router to use our enhanced history */ }
,
document.getElementById(‘mount’)
)
现在要怎么做啊
我看到他这个库貌似针对react-router并没有针对react-router-dom
2回答
-
吕小鸣
2019-04-09
同学你好,关于react-router-dom,history,react-router-redux这些模块我来给你解释一下哈。
react-router-dom:是react-router的DOM绑定模块,只有用了react-router-dom才能用类似<Route path="/about"></Route>,<Link></Link>这些组件。github。
history:是一个让你灵活控制或者模拟浏览器的历史操作的一个库,包括BrowserHistory,HashHistory,MemoryHistory,他可以脱离React使用,也可以结合React使用。github。
react-router-redux:简单来说就是你的项目如果用的React和Redux,如果想要用router的话就必须引入react-router-redux,他能帮你把router的状态放在store里来管理(注意根据你使用的react-router版本不同,会使用不同的版本)。github。
视频中只用的react-router-redux是5.xx版本的,但是目前该版本已经不再维护,只要保证相关模块的版本一直,是不影响正常使用的哈,取而代之的是新的版本connected-react-router,如果你想在你自己项目中用新版的,可以去网站上看下如和使用新的版本,另外关于router配置篇,可以参考一下我之前写的文档
062019-04-10 -
qq_没有美腿的宝马_0
提问者
2019-04-09
这个库都不维护的还有必要在开发中加上这个库吗
00
相似问题