javascript - react-router报错,'getCurrentLocation' of undefined
大家讲道理
大家讲道理 2017-04-11 11:16:13
[JavaScript讨论组]

照着文档来的,代码如下:


import React from 'react'
import ReactDOM from 'react-dom'
import { Router, Route, Link ,browserHistory} from 'react-router'
import { IndexRoute } from 'react-router'

const Dashboard = React.createClass({
  render() {
    return (

Welcome to the app!

) } }) const App = React.createClass({ render() { return (

App

  • About
  • Inbox
{this.props.children}

) } }) const About = React.createClass({ render() { return (

About

); } }) const Inbox = React.createClass({ render() { return (

Inbox

{this.props.children || "Welcome to your Inbox"}

) } }) const Message = React.createClass({ render() { return (

Message {this.props.params.id}

) } }) ReactDOM.render(( ), document.getElementById('root'))

但是会报错:

点进去后是这样的:

!history.getCurrentLocation ? process.env.NODE_ENV !== 'production' ? (0, _invariant2.default)(false, 'You have provided a history object created with history v2.x or ' + 'earlier. This version of React Router is only compatible with v3 ' + 'history objects. Please upgrade to history v3.x.') : (0, _invariant2.default)(false) : void 0;

到底是什么原因啊

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(2)
阿神
 import { Router, Route, Link, browserHistory } from 'react-router';
      
 ReactDOM.render((
  <Router history={browserHistory}>
      
  </Router>
),document.getElementById('id'));
  
  
阿神

我也遇到这个问题,我是着么解决的。

import {ReactDOM} from 'react-dom';
import { render } from 'react-dom';

在后面的ReactDOM.render换乘render类似这样

render(
    <Root rootHistory={historyMy} />,
    document.getElementById('root')
)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号