之前用react-router-dom v5 版本 配合 react-router-config https://www.npmjs.com/package/react-router-config https://reactrouter.com/
这么搞
目录结构:
router/index.js
import React from "react";
import { useRoutes } from "react-router-dom";
import LyMine from "../pages/mine";
import LyFriend from "../pages/friend";
import LyDiscover from "../pages/discover";
export default function Router() {
let routes = useRoutes([
{ path: "/discover", element: <LyDiscover /> },
{ path: "/mine", element: <LyMine /> },
{ path: "/friend", element: <LyFriend /> },
]);
return routes;
}
app.js
import React, { memo } from 'react'
import LyHeader from '@/components/app-header'
import LyFooter from '@/components/app-footer'
import { HashRouter } from 'react-router-dom'
import Router from '@/router'
const App = memo(() => {
return (
<HashRouter>
<LyHeader />
<Router />
<LyFooter />
</HashRouter>
)
})
export default App;
|