有人可以帮助我,我想使用React Router,但是我有一个无法修复的错误。
我的错误是:“反应路由器”不包含名为“ browserHistory”的导出。
我的下面的代码
谢谢^^
import React, { Component } from 'react'
import {Router, Route, Link,browserHistory,IndexRoute} from 'react-router'
import PostList from './containers/post_list'
class Routes extends Component {
render () {
return (
<div>
<Router history={browserHistory}>
<Route path="/" component={PostList}/>
</Router>
</div>
)
}
}
export default Routes
import React, { Component } from 'react'
class PostList extends Component {
render () {
return (
<div>
<h1>Liste des posts</h1>
</div>
)
}
}
export default PostList;
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import Routes from './routes.js';
import reducers from './reducers';
const createStoreWithMiddleware = applyMiddleware()(createStore);
ReactDOM.render(
<Provider store={createStoreWithMiddleware(reducers)}>
<Routes/>
</Provider>
, document.querySelector('.container'));
答案 0 :(得分:1)
React-Router v4不包含browserHistory
。
降级到v3或重写内容以使用v4。
例如参见https://github.com/ReactTraining/react-router/issues/4732
答案 1 :(得分:0)
感谢AKX ^^
正确的方法
import React, { Component } from 'react'
import { BrowserRouter, Route} from 'react-router-dom'
import PostList from './containers/post_list';
class Routes extends Component {
render () {
return (
<BrowserRouter>
<Route path="/new" component={PostList}/>
</BrowserRouter>
)
}
}
export default Routes