feat: update root layout

This commit is contained in:
Steven
2023-03-15 07:54:48 +08:00
parent 77b3f03f5a
commit c7d345f21d
6 changed files with 187 additions and 182 deletions

View File

@@ -1,6 +1,7 @@
import { createBrowserRouter, redirect } from "react-router-dom";
import { isNullorUndefined } from "../helpers/utils";
import { userService, workspaceService } from "../services";
import Root from "../layout/Root";
import Auth from "../pages/Auth";
import Home from "../pages/Home";
import UserDetail from "../pages/UserDetail";
@@ -14,52 +15,58 @@ const router = createBrowserRouter([
},
{
path: "/",
element: <Home />,
loader: async () => {
try {
await userService.initialState();
} catch (error) {
// do nth
}
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");
}
},
},
{
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");
}
},
},
{
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");
}
},
},
{
path: "/:workspaceName",
element: <WorkspaceDetail />,
loader: async () => {
try {
await userService.initialState();
await workspaceService.fetchWorkspaceList();
} catch (error) {
// do nth
}
const { user } = userService.getState();
if (isNullorUndefined(user)) {
return redirect("/user/auth");
}
},
},
{
path: "/:workspaceName",
element: <WorkspaceDetail />,
loader: async () => {
try {
await userService.initialState();
await workspaceService.fetchWorkspaceList();
} catch (error) {
// do nth
}
const { user } = userService.getState();
if (isNullorUndefined(user)) {
return redirect("/user/auth");
}
},
const { user } = userService.getState();
if (isNullorUndefined(user)) {
return redirect("/user/auth");
}
},
},
],
},
{
path: "/:workspaceName/:shortcutName",