# 一、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>
最后更新于: 5/17/2021, 10:39:45 PM