init: Init React Application
This commit is contained in:
17
src/app/index.tsx
Normal file
17
src/app/index.tsx
Normal file
@ -0,0 +1,17 @@
|
||||
import * as React from "react";
|
||||
|
||||
import { BrowserRouter } from "react-router-dom";
|
||||
|
||||
import { Router } from "./router";
|
||||
import { theme } from "@shared";
|
||||
import { ThemeProvider } from "@mui/material/styles";
|
||||
import { ToastContainer } from "react-toastify";
|
||||
|
||||
export const App: React.FC = () => (
|
||||
<ThemeProvider theme={theme}>
|
||||
<ToastContainer />
|
||||
<BrowserRouter>
|
||||
<Router />
|
||||
</BrowserRouter>
|
||||
</ThemeProvider>
|
||||
);
|
33
src/app/router/index.tsx
Normal file
33
src/app/router/index.tsx
Normal file
@ -0,0 +1,33 @@
|
||||
import { DevicesPage, LoginPage, MainPage, SightPage } from "@pages";
|
||||
import { authStore } from "@shared";
|
||||
import { Layout } from "@widgets";
|
||||
|
||||
import { Navigate, Outlet, Route, Routes } from "react-router-dom";
|
||||
|
||||
const ProtectedRoute = ({ children }: { children: React.ReactNode }) => {
|
||||
const { isAuthenticated } = authStore;
|
||||
if (!isAuthenticated) {
|
||||
return <Navigate to="/login" />;
|
||||
}
|
||||
return children;
|
||||
};
|
||||
export const Router = () => {
|
||||
return (
|
||||
<Routes>
|
||||
<Route
|
||||
path="/"
|
||||
element={
|
||||
<Layout>
|
||||
<Outlet />
|
||||
</Layout>
|
||||
}
|
||||
>
|
||||
<Route path="/" element={<MainPage />} />
|
||||
<Route path="/sights" element={<SightPage />} />
|
||||
<Route path="/devices" element={<DevicesPage />} />
|
||||
</Route>
|
||||
|
||||
<Route path="/login" element={<LoginPage />} />
|
||||
</Routes>
|
||||
);
|
||||
};
|
Reference in New Issue
Block a user