开发者问题收集

我的浏览史和反应途径有错误

2018-08-01
102

有人可以帮助我,我想使用 React Router,但是我有一个无法修复的错误。

我的错误是:“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'));
2个回答

React-Router v4 不包含 browserHistory

请降级到 v3 或重写以使用 v4。

例如,请参阅 https://github.com/ReactTraining/react-router/issues/4732

AKX
2018-08-01

感谢 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
mathieu ka
2018-08-01