# 一、React项目划分路由
- 安装 :
yarn add react-router-dom
yarn add react-router-config
进行单独文件配置管理 - 配置 :
- 在
router/index.js
下配置相关路由 - 在对应的主页面中
renderRoutes
- 在
// router/index.js
import Discover from "../pages/discover";
import Friends from "../pages/friends";
import Mine from "../pages/mine";
const routes = [
{
path: "/",
exact: true,
component: Discover
},
{
path: "/",
component: Friends
},
{
path: "/",
component: Mine
},
];
export default routes;
// App.js
<HashRouter>
<AppHeader />
{
renderRoutes(routes)
}
<AppFooter />
</HashRouter>