javascript-React Router和历史记录
作者:互联网
您好,我真的很新来,我正在看Learncode.academy上的这个很棒的youtube ReactJs教程.本教程来自去年,我不知道这些模块是否已被弃用.我收到以下错误消息:
You have provided a history object created with history v4.x or v2.x and earlier. This version of React Router is only compatible with v3 history objects. Please change to history v3.x. at invariant Here is my code:
import Layout from "./components/Layout";
import { Router, Route, IndexRoute, browserHistory } from "react-router";
const app = document.getElementById('app');
ReactDOM.render(
<Router history="{browserHistory}">
<Route path="/" component="{Layout}">
</Route>
</Router>,
app);
这是我的package.json
"history": "^3.2.1",
"react-router": "^3.0.2",
任何建议将不胜感激!谢谢!
解决方法:
您使用的历史记录和组件不正确.您不需要在历史记录和组件对象周围加引号
import Layout from "./components/Layout";
import { Router, Route, IndexRoute, browserHistory } from "react-router";
const app = document.getElementById('app');
ReactDOM.render(
<Router history={browserHistory}>
<Route path="/" component={Layout}>
</Route>
</Router>,
app);
标签:ecmascript-6,reactjs,react-router,javascript 来源: https://codeday.me/bug/20191026/1935501.html