admin管理员组文章数量:1415145
Hello I'm really new to react and I'm watching this wonderful youtube ReactJs tutorial from Learncode.academy. This tutorial is from last year I don't know if these modules are already deprecated. I got these error messages:
You have provided a history object created with history v4.x or v2.x and earlier. This version of React Router is only patible with v3 history objects. Please change to history v3.x. at invariant Here is my code:
import Layout from "./ponents/Layout";
import { Router, Route, IndexRoute, browserHistory } from "react-router";
const app = document.getElementById('app');
ReactDOM.render(
<Router history="{browserHistory}">
<Route path="/" ponent="{Layout}">
</Route>
</Router>,
app);
Here is my package.json
"history": "^3.2.1",
"react-router": "^3.0.2",
Any suggestion would be highly appreciated! Thanks!
Hello I'm really new to react and I'm watching this wonderful youtube ReactJs tutorial from Learncode.academy. This tutorial is from last year I don't know if these modules are already deprecated. I got these error messages:
You have provided a history object created with history v4.x or v2.x and earlier. This version of React Router is only patible with v3 history objects. Please change to history v3.x. at invariant Here is my code:
import Layout from "./ponents/Layout";
import { Router, Route, IndexRoute, browserHistory } from "react-router";
const app = document.getElementById('app');
ReactDOM.render(
<Router history="{browserHistory}">
<Route path="/" ponent="{Layout}">
</Route>
</Router>,
app);
Here is my package.json
"history": "^3.2.1",
"react-router": "^3.0.2",
Any suggestion would be highly appreciated! Thanks!
Share Improve this question edited Jan 26, 2017 at 6:34 mplungjan 179k28 gold badges182 silver badges240 bronze badges asked Jan 26, 2017 at 6:24 Frank MendezFrank Mendez 5723 gold badges13 silver badges28 bronze badges 1- Check this out: stackoverflow./questions/40455999/… Might help – Ricky Mutschlechner Commented Jan 26, 2017 at 6:36
2 Answers
Reset to default 3You are using the history and the ponents incorrectly. You dont need quotes around the history and ponent objects
import Layout from "./ponents/Layout";
import { Router, Route, IndexRoute, browserHistory } from "react-router";
const app = document.getElementById('app');
ReactDOM.render(
<Router history={browserHistory}>
<Route path="/" ponent={Layout}>
</Route>
</Router>,
app);
From https://github./ReactTraining/react-router/issues/353
To get basename working for [email protected]:
npm install --save [email protected]
npm install --save history@^3.0.0
(check react-router package.json to get the correct history version to use, current major version of history is 4.x and won't work with [email protected])
import React from 'react'
import { render } from 'react-dom'
import { Router, Route, IndexRoute, useRouterHistory } from 'react-router'
import { createHistory } from 'history'
const history = useRouterHistory(createHistory)({
basename: '/subdirectory-where-the-app-is-hosted-goes-here'
})
render((
<Router history={history}>
<Route path='/' ponent={Layout}>
<IndexRoute ponent={HomeView} />
<Route path='other-views' ponent={OtherViews} />
</Route>
</Router>
), document.getElementById('main'))
本文标签: javascriptReact Router and HistoryStack Overflow
版权声明:本文标题:javascript - React Router and History - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745227580a2648680.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论