add project structure
This commit is contained in:
1 parent
07fc6c0b6c
commit
6eaf18285a
28 files changed
+1309
-648
No files matched your search
@@ -0,0 +1,21 @@
|
||||
import { Navigate, Outlet, useLocation } from 'react-router-dom'
|
||||
|
||||
import { localStorageKeys } from '@constants/localStorageKeys.ts'
|
||||
|
||||
import { LocalStorage } from '@utils/localStorageUtils.ts'
|
||||
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
const PrivateRoute = () => {
|
||||
const location = useLocation()
|
||||
const userToken = LocalStorage.get(localStorageKeys.USER_TOKEN)
|
||||
|
||||
if (!userToken) {
|
||||
LocalStorage.set('redirectUrl', location.pathname)
|
||||
return <Navigate to={routePaths.login} replace />
|
||||
}
|
||||
|
||||
return <Outlet />
|
||||
}
|
||||
|
||||
export default PrivateRoute
|
||||
@@ -0,0 +1,29 @@
|
||||
import { App } from 'antd'
|
||||
import { Route, Routes } from 'react-router-dom'
|
||||
|
||||
import ErrorPage from '@components/ErrorPage'
|
||||
import Layout from '@components/Layout'
|
||||
|
||||
import HomePages from '@pages/HomePage'
|
||||
import LoginPage from '@pages/LoginPage'
|
||||
|
||||
import PrivateRoute from '@routes/PrivateRoute'
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
|
||||
const Routers = () => {
|
||||
return (
|
||||
<App>
|
||||
<Routes>
|
||||
<Route element={<PrivateRoute />}>
|
||||
<Route path="/" element={<Layout />}>
|
||||
<Route index element={<HomePages />} />
|
||||
</Route>
|
||||
</Route>
|
||||
<Route path={routePaths.login} element={<LoginPage />} />
|
||||
<Route path={routePaths.error} element={<ErrorPage />} />
|
||||
</Routes>
|
||||
</App>
|
||||
)
|
||||
}
|
||||
|
||||
export default Routers
|
||||
@@ -0,0 +1,8 @@
|
||||
type RoutePaths = 'home' | 'notFound' | 'error' | 'login'
|
||||
|
||||
export const routePaths: Record<RoutePaths, string> = {
|
||||
home: '/',
|
||||
error: '/error',
|
||||
notFound: '*',
|
||||
login: '/login'
|
||||
}
|
||||
Reference in new issue
Block a user