chore: update initial global loader

This commit is contained in:
Steven
2023-10-08 20:31:38 +08:00
parent 31997936d6
commit 3ff4d19782
4 changed files with 18 additions and 35 deletions

View File

@ -18,21 +18,14 @@ const Resources = lazy(() => import("@/pages/Resources"));
const Setting = lazy(() => import("@/pages/Setting"));
const NotFound = lazy(() => import("@/pages/NotFound"));
const initialGlobalStateLoader = (() => {
let done = false;
return async () => {
if (done) {
return;
}
done = true;
try {
await initialGlobalState();
} catch (error) {
// do nth
}
};
})();
const initialGlobalStateLoader = async () => {
try {
await initialGlobalState();
} catch (error) {
// do nth
}
return null;
};
const initialUserStateLoader = async (redirectWhenNotFound = true) => {
let user = undefined;
@ -52,10 +45,7 @@ const router = createBrowserRouter([
{
path: "/",
element: <App />,
loader: async () => {
await initialGlobalStateLoader();
return null;
},
loader: () => initialGlobalStateLoader(),
children: [
{
path: "/auth",