[英]React router history is string?
I'm trying to get started with react router in the browser using hash history, I copied this code from the guide for version 3. 我正在尝试使用哈希历史记录在浏览器中开始使用React Router,我从版本3的指南中复制了此代码。
import React from "react";
import ReactDOM from "react-dom";
import { Router, Route, Link, hashHistory } from 'react-router';
const App = React.createClass({
render() {
return (
<div>
<h1>App</h1>
<ul>
<li><Link to="/about">About</Link></li>
<li><Link to="/inbox">Inbox</Link></li>
</ul>
{this.props.children}
</div>
)
}
})
const About = React.createClass({
render() {
return <h3>About</h3>
}
})
const Inbox = React.createClass({
render() {
return (
<div>
<h2>Inbox</h2>
{this.props.children || "Welcome to your Inbox"}
</div>
)
}
})
const Message = React.createClass({
render() {
return <h3>Message {this.props.params.id}</h3>
}
})
var history = hashHistory;
console.log(history);
ReactDOM.render((
<Router history="{history}">
<Route path="/" component={App}>
<Route path="about" component={About} />
<Route path="inbox" component={Inbox}>
<Route path="messages/:id" component={Message} />
</Route>
</Route>
</Router>
),
document.getElementById('app-root'));
When I open the document I get these errors 当我打开文档时出现这些错误
Warning: Failed prop type: Invalid prop
history
of typestring
supplied toRouter
, expectedobject
. 警告:prop类型失败:提供给Router
string
类型propobject
history
无效,期望object
。
I logged history
before that and it looks like an object 我在此之前记录了history
,它看起来像一个对象
Uncaught Error: You have provided a history object created with history v4.x or v2.x and earlier. 未捕获的错误:您提供了使用历史记录v4.x或v2.x及更早版本创建的历史记录对象。 This version of React Router is only compatible with v3 history objects. 此版本的React Router仅与v3历史记录对象兼容。 Please change to history v3.x. 请更改为历史记录v3.x。
I have installed react-router@3
along with history@3
, I can confirm 我已经安装了react-router@3
和history@3
,我可以确认
+-- react-router@3.0.2 extraneous +-react-router@3.0.2无关
I can't find history
in the list but if I go to the directory I can see the package.json
我在列表中找不到history
,但是如果我转到目录,则可以看到package.json
"version": "3.3.0"
从历史记录中删除“”符号
<Router history={history}>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.