diff --git a/src/components/app/app.tsx b/src/components/app/app.tsx index c6f2038..7e447a9 100644 --- a/src/components/app/app.tsx +++ b/src/components/app/app.tsx @@ -1,9 +1,45 @@ import React from 'react'; +import {BrowserRouter, Route, Routes} from 'react-router-dom'; import {MainScreen} from '../../pages/main-screen/main-screen.tsx'; import {MainScreenProps} from '../../props/main-screen-props.ts'; +import {LoginScreen} from '../../pages/login-screen/login-screen.tsx'; +import {OfferScreen} from '../../pages/offer-screen/offer-screen.tsx'; +import {NotFoundScreen} from '../../pages/not-found-screen/not-found-screen.tsx'; +import {AppRoute, AuthorizationStatus} from '../../const.ts'; +import {PrivateRoute} from '../private-route/private-route.tsx'; +import {FavoriteScreen} from '../../pages/favorites-screen/favorite-screen.tsx'; export function App({placeCount}: MainScreenProps): React.JSX.Element { return ( - + + + } + /> + } + /> + } + /> + + + + } + /> + } + /> + + ); } diff --git a/src/components/private-route/private-route.tsx b/src/components/private-route/private-route.tsx new file mode 100644 index 0000000..c666a2a --- /dev/null +++ b/src/components/private-route/private-route.tsx @@ -0,0 +1,18 @@ +import {JSX} from 'react'; +import {Navigate} from 'react-router-dom'; +import {AppRoute, AuthorizationStatus} from '../../const'; + +type PrivateRouteProps = { + authorizationStatus: AuthorizationStatus; + children: JSX.Element; +} + +export function PrivateRoute(props: PrivateRouteProps): JSX.Element { + const {authorizationStatus, children} = props; + + return ( + authorizationStatus === AuthorizationStatus.Auth + ? children + : + ); +} diff --git a/src/const.ts b/src/const.ts new file mode 100644 index 0000000..79d34d4 --- /dev/null +++ b/src/const.ts @@ -0,0 +1,12 @@ +export enum AppRoute { + Main = '/', + Login = '/login', + Favorites = '/favorites', + Offer = '/offer/:id' +} + +export enum AuthorizationStatus { + Auth = 'AUTH', + NoAuth = 'NO_AUTH', + Unknown = 'UNKNOWN', +} diff --git a/src/pages/not-found-screen/not-found-screen.tsx b/src/pages/not-found-screen/not-found-screen.tsx new file mode 100644 index 0000000..c8fb787 --- /dev/null +++ b/src/pages/not-found-screen/not-found-screen.tsx @@ -0,0 +1,13 @@ +import {JSX} from 'react'; + +export function NotFoundScreen() : JSX.Element { + return ( + +
+

404 Not Found

+

Извините, страница не найдена.

+ На главную +
+ + ); +}