使用react-router 4.0.0的路由器历史记录 [英] Router history with react-router 4.0.0
本文介绍了使用react-router 4.0.0的路由器历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 react-router 4.0.0
中,历史记录似乎已经改变,使用以下 index.js
In react-router 4.0.0
the history provisoning seems to have changed, with the following index.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, hashHistory } from 'react-router';
import App from './components/App';
import './index.css';
ReactDOM.render(
<Router history={hashHistory}>
<Route path="/" component={App} />
</Router>, document.getElementById('root')
);
我得到:
Warning: Failed prop type: The prop `history` is marked as required in `Router`, but its value is `undefined`.
之后出现错误。我浏览了代码,但无法找到任何示例或API如何更改。
and an error afterwards. I browsed the code but can't find any example or API how that has changed.
推荐答案
React Router v4改变了一点点。他们制作了单独的顶级路由器元素。在代码中使用< HashRouter>
替换<路径历史= {hashHistory}>
。
React Router v4 changed things little bit. They made separate top level router elements. Replace <Router history={hashHistory}>
with <HashRouter>
in your code.
希望这会有所帮助。
import {HashRouter,Route} from 'react-router-dom';
<HashRouter>
<Route path = "/getapp" component = {MainApp} />
</HashRouter>
这篇关于使用react-router 4.0.0的路由器历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文