[react-router.v4] Uncaught TypeE
2019-02-22 本文已影响0人
德拉T
-
选择 react-router 和 react-router-dom
只需引用一个,两者之处就是dom多了<Link> <BrowserRouter>这样的 DOM 类组件 -
报错 Uncaught TypeError: Cannot read property 'location' of undefined
impt 引用时写
import React from "react";
import { render } from "react-dom";
import { BrowserRouter as Router, Route, Link } from "react-router-dom";
const Home = () => {
return (
<div>
<h1>test home</h1>
</div>
);
};
const about = () => {
return (
<div>
<h1>test about</h1>
</div>
);
};
const topics = () => {
return (
<div>
<h1>test topics</h1>
</div>
);
};
render(
<Router>
<div>
<ul>
<li>
<Link to="/">首页</Link>
</li>
<li>
<Link to="/about">关于</Link>
</li>
<li>
<Link to="/topics">主题列表</Link>
</li>
</ul>
<Route exact path="/" component={Home} />
<Route path="/about" component={about} />
<Route path="/topics" component={topics} />
</div>
</Router>,
document.getElementById("root")
);