diff --git a/src/components/app/app.tsx b/src/components/app/app.tsx index c275cf3..19a8337 100644 --- a/src/components/app/app.tsx +++ b/src/components/app/app.tsx @@ -1,5 +1,11 @@ import MainScreen from '../../pages/main-screen/main-screen'; - +import {BrowserRouter, Route, Routes} from 'react-router-dom'; +import LoginScreen from '../../pages/login-screen/login-screen.tsx'; +import FavoritesScreen from '../../pages/favorites-screen/favorites-screen.tsx'; +import NotFoundScreen from '../../pages/not-found-screen/not-found-screen.tsx'; +import OfferScreen from '../../pages/offer-screen/offer-screen.tsx'; +import PrivateRoute from '../private-route/private-route.tsx'; +import { AppRoute, AuthorizationStatus } from '../../const.ts'; type AppScreenProps = { placesCount: number; @@ -7,7 +13,22 @@ type AppScreenProps = { function App({placesCount}: AppScreenProps): JSX.Element { return ( - + + + } /> + } /> + + + + } + /> + } /> + } /> + + ); } export default App; diff --git a/src/components/private-route/private-route.tsx b/src/components/private-route/private-route.tsx new file mode 100644 index 0000000..36c4c44 --- /dev/null +++ b/src/components/private-route/private-route.tsx @@ -0,0 +1,15 @@ +import {Navigate} from 'react-router-dom'; +import { AppRoute, AuthorizationStatus } from '../../const'; + +type PrivateRouteProps = { + authorizationStatus: AuthorizationStatus; + children: JSX.Element; +} + +function PrivateRoute(props: PrivateRouteProps): JSX.Element { + const {authorizationStatus, children} = props; + return ( + authorizationStatus === AuthorizationStatus.Auth ? children : + ); +} +export default PrivateRoute; diff --git a/src/const.ts b/src/const.ts index 26c1ca3..5f47f3c 100644 --- a/src/const.ts +++ b/src/const.ts @@ -1,4 +1,16 @@ -const Settings = { +export const Settings = { placesCount: 55, } as const; -export default Settings; + +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/index.tsx b/src/index.tsx index 155bb11..7b62b8d 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -1,7 +1,7 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; import App from './components/app/app'; -import Settings from './const'; +import { Settings } from './const'; const root = ReactDOM.createRoot( document.getElementById('root') as HTMLElement 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..f6faeeb --- /dev/null +++ b/src/pages/not-found-screen/not-found-screen.tsx @@ -0,0 +1,9 @@ +function NotFoundScreen(): JSX.Element { + return ( +
+

404 Not Found

+ Вернуться на главную +
+ ); +} +export default NotFoundScreen;