1 回答
TA贡献1893条经验 获得超10个赞
你可以Switch搬到Home.js:
import React from "react";
import { BrowserRouter as Router, Switch, Route } from "react-router-dom";
import HomeNav from "./NavBar";
import "./NavBar.css";
import Account from "./Account";
import Friends from "./Friends";
class Home extends React.Component {
render() {
return (
<div>
<Router>
<HomeNav />
<h1>
"this is the friends/account tab" <br />text should be here
</h1>
<Switch>
<Route path="/account" component={Account} />
<Route path="/friends" component={Friends} />
</Switch>
</Router>
</div>
);
}
}
export default Home;
只放链接Routing.js
class Routing extends React.Component {
render() {
return (
<div>
<ul>
<li>
<Link to="/friends">friends</Link>
</li>
<li>
<Link to="/account">account</Link>
</li>
</ul>
</div>
);
}
}
据我了解,组件仅在Switch声明的位置显示。
添加回答
举报