mirror of
https://github.com/PlayEdu/h5.git
synced 2025-12-25 13:16:54 +08:00
项目初始化
This commit is contained in:
49
src/routes/index.tsx
Normal file
49
src/routes/index.tsx
Normal file
@@ -0,0 +1,49 @@
|
||||
import { lazy } from "react";
|
||||
import { RouteObject } from "react-router-dom";
|
||||
import { system, user } from "../api";
|
||||
|
||||
import { getToken } from "../utils";
|
||||
import { InitPage } from "../pages/init";
|
||||
import IndexPage from "../pages/index/index";
|
||||
import LoginPage from "../pages/login";
|
||||
import PrivateRoute from "../components/private-route";
|
||||
|
||||
let RootPage: any = null;
|
||||
if (getToken()) {
|
||||
RootPage = lazy(async () => {
|
||||
return new Promise<any>(async (resolve) => {
|
||||
try {
|
||||
let configRes: any = await system.config();
|
||||
let userRes: any = await user.detail();
|
||||
resolve({
|
||||
default: (
|
||||
<InitPage configData={configRes.data} loginData={userRes.data} />
|
||||
),
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("系统初始化失败", e);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
RootPage = <InitPage />;
|
||||
}
|
||||
|
||||
const routes: RouteObject[] = [
|
||||
{
|
||||
path: "/",
|
||||
element: RootPage,
|
||||
children: [
|
||||
{
|
||||
path: "/",
|
||||
element: <IndexPage />,
|
||||
},
|
||||
{
|
||||
path: "/login",
|
||||
element: <LoginPage />,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
export default routes;
|
||||
Reference in New Issue
Block a user