1. 安装
yarn add react-router-dom
2.router.js
/*
* @Author: zulezhe
* @Date: 2021-12-23 09:15:06
* @LastEditors: wangchaoxu
* @LastEditTime: 2021-12-23 09:15:53
* @Path: https://gitee.com/zulezhe/
* @Description:
*/
import Login from "../pages/login/Login";
import Home from "../pages/home/home";
import User from "../pages/user";
import UserTwo from "../pages/usertow";
import Demo1 from "../pages/routerDemo/demo1";
import Demo2 from "../pages/routerDemo/demo2";
import Demo3 from "../pages/routerDemo/demo3";
interface router {
path: string;
component: any;
exact?: boolean;
children?: Array<router>;
}
const routers: Array<router> = [
{
path: "/",
exact: true,
component: Login,
},
{
path: "/home",
component: Home,
children: [
{
path: "/",
component: Demo1,
},
{
path: "/home/demo2",
component: Demo2,
},
{
path: "/home/demo3",
component: Demo3,
},
],
},
{
path: "/home",
component: Home,
},
{
path: "/user",
component: User,
},
{
path: "/user/:userId",
component: UserTwo,
},
];
export default routers;