请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

import createHistory from 'history/createHashHistory';

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

正在回答 回答被采纳积分+3

2回答

吕小鸣 2019-04-09 16:35:12

同学你好,关于react-router-dom,history,react-router-redux这些模块我来给你解释一下哈。

  1.  react-router-dom:是react-router的DOM绑定模块,只有用了react-router-dom才能用类似<Route path="/about"></Route>,<Link></Link>这些组件。github

  2. history:是一个让你灵活控制或者模拟浏览器的历史操作的一个库,包括BrowserHistory,HashHistory,MemoryHistory,他可以脱离React使用,也可以结合React使用。github

  3. react-router-redux:简单来说就是你的项目如果用的React和Redux,如果想要用router的话就必须引入react-router-redux,他能帮你把router的状态放在store里来管理(注意根据你使用的react-router版本不同,会使用不同的版本)。github

视频中只用的react-router-redux是5.xx版本的,但是目前该版本已经不再维护,只要保证相关模块的版本一直,是不影响正常使用的哈,取而代之的是新的版本connected-react-router,如果你想在你自己项目中用新版的,可以去网站上看下如和使用新的版本,另外关于router配置篇,可以参考一下我之前写的文档

0 回复 有任何疑惑可以回复我~
  • 我用最新版的connected-react-router去配置了一整个东西但是路由切换的时候http://localhost:8080/home 并没有启动history。。很奇怪
    回复 有任何疑惑可以回复我~ 2019-04-09 17:43:56
  • http://localhost:8080/home.index#/my我的就不是这样的。。。很奇怪
    回复 有任何疑惑可以回复我~ 2019-04-09 17:45:57
  • 我找了很久了,是在找不到原因了,可以麻烦帮我想下哪儿出了问题啊
    回复 有任何疑惑可以回复我~ 2019-04-09 17:46:40
提问者 qq_没有美腿的宝马_0 2019-04-09 15:50:37

这个库都不维护的还有必要在开发中加上这个库吗

0 回复 有任何疑惑可以回复我~
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信