React-router 4.0.0 的路由器历史记录

2024-03-24

In react-router 4.0.0历史提供似乎已经改变,如下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')
);

I get:

Warning: Failed prop type: The prop `history` is marked as required in `Router`, but its value is `undefined`.

之后出现错误。我浏览了代码,但找不到任何示例或 API 来说明它是如何改变的。


React Router v4 改变了一点点。他们制作了单独的顶级路由器元素。代替<Router history={hashHistory}> with <HashRouter>在你的代码中。

希望这会有所帮助。

import {HashRouter,Route} from 'react-router-dom';

<HashRouter>
    <Route path = "/getapp" component = {MainApp} />
</HashRouter>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

React-router 4.0.0 的路由器历史记录 的相关文章

随机推荐