warning.js:36警告:支柱类型失败:支柱`history`在`Router`中标记为必需,但其值为'undefined`

时间:2017-07-07 13:49:57

标签: javascript reactjs react-router react-router-dom

根据以下代码获取标题中的错误:

import React from 'react'
// import { browserHistory, hashHistory, Router } from 'react-router'
// import createMemoryHistory from 'history/lib/createMemoryHistory'
import { browserHistory, hashHistory, Router, Route, Switch } from 'react-router-dom'
import Portfolio from './portfolio/Portfolio'
import Home from './home/Home'
import NoMatch from './NoMatch'

// const history = createMemoryHistory(location);
// console.log('history', history);

const Routes = () => {
    return (
        <Router history={browserHistory}>
            <Route exact={ true } path="/" component={ Home }/>
            <Route exact={ true } path="/portfolio" component={ Portfolio }/>
            <Route component={ NoMatch } />
        </Router>
    );
}

export default Routes

enter image description here

1 个答案:

答案 0 :(得分:2)

将Router更换为BrowserRouter并使用Switch作为react-router-dom version4.0,路由器不能有多个子节点。

/tmp/mnist_convnet_model

并用以下代码替换路线:

import { browserHistory, hashHistory, BrowserRouter, Route, Switch } from 'react-router-dom';