mirror of
https://github.com/aykhans/slash-e.git
synced 2025-07-06 21:22:36 +00:00
chore: rename folders
This commit is contained in:
56
web/src/routers/index.tsx
Normal file
56
web/src/routers/index.tsx
Normal file
@ -0,0 +1,56 @@
|
||||
import { createBrowserRouter, redirect } from "react-router-dom";
|
||||
import { isNullorUndefined } from "../helpers/utils";
|
||||
import { userService } from "../services";
|
||||
import Root from "../layouts/Root";
|
||||
import Auth from "../pages/Auth";
|
||||
import Home from "../pages/Home";
|
||||
import UserDetail from "../pages/UserDetail";
|
||||
|
||||
const router = createBrowserRouter([
|
||||
{
|
||||
path: "/user/auth",
|
||||
element: <Auth />,
|
||||
},
|
||||
{
|
||||
path: "/",
|
||||
element: <Root />,
|
||||
children: [
|
||||
{
|
||||
path: "",
|
||||
element: <Home />,
|
||||
loader: async () => {
|
||||
try {
|
||||
await userService.initialState();
|
||||
} catch (error) {
|
||||
// do nth
|
||||
}
|
||||
|
||||
const { user } = userService.getState();
|
||||
if (isNullorUndefined(user)) {
|
||||
return redirect("/user/auth");
|
||||
}
|
||||
return null;
|
||||
},
|
||||
},
|
||||
{
|
||||
path: "/account",
|
||||
element: <UserDetail />,
|
||||
loader: async () => {
|
||||
try {
|
||||
await userService.initialState();
|
||||
} catch (error) {
|
||||
// do nth
|
||||
}
|
||||
|
||||
const { user } = userService.getState();
|
||||
if (isNullorUndefined(user)) {
|
||||
return redirect("/user/auth");
|
||||
}
|
||||
return null;
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
export default router;
|
Reference in New Issue
Block a user