使用react-router-config配置路由

安装react-router-config
yarn add react-router-config


App.js

import {
      renderRoutes } from 'react-router-config';
import {
      HashRouter } from 'react-router-dom';

//routes 是路由配置文件
import routes from "./router";
...

//renderRoutes需要Router包裹
<HashRouter>
	{
     renderRouters(routes)}
</HashRouter>

=>
router.js

//配置页面

//导入页面
import HYDiscover from "@/pages/discover";
import HYFriends from "@/pages/friends";
import HYMine from "@/pages/mine";

const routes = [
    {
     
        path: '/',
        exact: true,
        component: HYDiscover
    },
    {
     
        path: '/friends',
        component: HYFriends
    },
    {
     
        path: '/mine',
        component: HYMine
    }
]

export default routes

你可能感兴趣的:(学习笔记,javascript,reactjs)