ibms-dome/ibms_react/src/routes/routes.js

83 lines
2.0 KiB
JavaScript
Raw Normal View History

2023-01-31 23:15:50 +08:00
import Login from "@/pages/Login";
import App from "@/App";
import Home from "@/pages/Home";
import Monitor from "@/pages/Monitor";
import Energy from "@/pages/Energy";
import History from "@/pages/History";
import Alert from "@/pages/Alert";
import Operation from "@/pages/Operation";
import GraphManagement from "@/pages/GraphManagement";
import AccountManagement from "@/pages/AccountManagement";
import { redirect } from "react-router-dom";
import { setUserAccountByBaja, userLogin } from "@UTIL/index";
const monitor = [{}, {}];
const routes = [
{
path: "/",
element: <App />,
loader: async () => {
let JWT_Authorization = document.cookie.replace(
/(?:(?:^|.*;\s*)JWT-Authorization\s*\=\s*([^;]*).*$)|^.*$/,
"$1",
);
console.log(JWT_Authorization);
2023-02-06 00:06:41 +08:00
if (window.location.href.includes("localhost:3000") && !JWT_Authorization) {
2023-01-31 23:15:50 +08:00
return redirect("/login");
} else if (window.location.href.includes("http://220.132.206.5") && !JWT_Authorization) {
const account = await setUserAccountByBaja();
console.log("account", account);
await userLogin(
null,
{
account,
password: "rJ2T5Kkj",
},
null,
);
return null;
}
return null;
},
children: [
{
index: true,
element: <Home />,
},
{
path: "monitor/:systemId",
element: <Monitor />,
children: monitor,
},
{
path: "energy",
element: <Energy />,
},
{
path: "history",
element: <History />,
},
{
path: "alert",
element: <Alert />,
},
{
path: "operation",
element: <Operation />,
},
{
path: "graphManagement",
element: <GraphManagement />,
},
{
path: "accountManagement",
element: <AccountManagement />,
},
],
},
{
path: "/login",
element: <Login />,
},
];
export default routes;