-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
111 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,39 @@ | ||
import MainPage from '../pages/main-page'; | ||
import OfferPage from '../pages/offer-page'; | ||
import FavoritePage from '../pages/favorite-page'; | ||
import LoginPage from '../pages/login-page'; | ||
import { Route, Routes } from 'react-router-dom'; | ||
import { AppRoute, authorizationStatus } from '../const'; | ||
import NotFoundPage from '../pages/not-found-page'; | ||
import ProtectedRoute from './protected-route'; | ||
|
||
type TAppProps = { | ||
count: number; | ||
} | ||
|
||
export default function App({ count }: TAppProps) { | ||
return ( | ||
<MainPage count={count} /> | ||
<Routes> | ||
<Route | ||
path={AppRoute.Main} | ||
element={<MainPage count={count} />} | ||
/> | ||
<Route | ||
path={AppRoute.Offer} | ||
element={<OfferPage />} | ||
/> | ||
<Route | ||
path={AppRoute.Favorites} | ||
element={<ProtectedRoute hasAccess={authorizationStatus.NoAuth}><FavoritePage /></ProtectedRoute>} | ||
/> | ||
<Route | ||
path={AppRoute.Login} | ||
element={<LoginPage />} | ||
/> | ||
<Route | ||
path='*' | ||
element={<NotFoundPage />} | ||
/> | ||
</Routes> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ReactNode } from 'react'; | ||
import { Navigate } from 'react-router-dom'; | ||
import { AppRoute } from '../const'; | ||
|
||
type TProtectedRouteProps = { | ||
children: ReactNode; | ||
hasAccess: boolean; | ||
} | ||
|
||
export default function ProtectedRoute({ hasAccess, children }: TProtectedRouteProps) { | ||
if (hasAccess) { | ||
return children; | ||
} | ||
|
||
return <Navigate to={AppRoute.Login} />; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export enum AppRoute { | ||
Login = '/login', | ||
Main = '/', | ||
Favorites = '/favorites', | ||
Offer = '/offer', | ||
} | ||
|
||
export const authorizationStatus = { | ||
Auth: true, | ||
NoAuth: false, | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import App from './components/app'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import { HelmetProvider } from 'react-helmet-async'; | ||
|
||
const root = ReactDOM.createRoot( | ||
document.getElementById('root') as HTMLElement | ||
); | ||
|
||
root.render( | ||
<React.StrictMode> | ||
<App count={5} /> | ||
<HelmetProvider> | ||
<BrowserRouter> | ||
<App count={5} /> | ||
</BrowserRouter> | ||
</HelmetProvider> | ||
</React.StrictMode> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Link } from 'react-router-dom'; | ||
import { AppRoute } from '../const'; | ||
|
||
const divStyle = { | ||
position: 'absolute', | ||
top: '50%', | ||
left: '50%', | ||
textAlign: 'center' | ||
}; | ||
|
||
export default function NotFoundPage() { | ||
return ( | ||
<div style={divStyle}> | ||
<h1>404 Not Found</h1> | ||
<Link to={AppRoute.Main}> | ||
<p>На глваную страницу</p> | ||
</Link> | ||
</div> | ||
); | ||
} |