feat: use react-router

This commit is contained in:
Steven
2022-09-19 21:53:27 +08:00
parent 4608894e56
commit 307483e499
12 changed files with 155 additions and 149 deletions

47
web/src/router/index.tsx Normal file
View File

@ -0,0 +1,47 @@
import { createBrowserRouter } from "react-router-dom";
import { userService } from "../services";
import Auth from "../pages/Auth";
import Explore from "../pages/Explore";
import Home from "../pages/Home";
const router = createBrowserRouter([
{
path: "/",
element: <Home />,
loader: async () => {
try {
await userService.initialState();
} catch (error) {
// do nth
}
},
},
{
path: "/auth",
element: <Auth />,
},
{
path: "/u/:userId",
element: <Home />,
loader: async () => {
try {
await userService.initialState();
} catch (error) {
// do nth
}
},
},
{
path: "/explore",
element: <Explore />,
loader: async () => {
try {
await userService.initialState();
} catch (error) {
// do nth
}
},
},
]);
export default router;