Skip to content

Commit

Permalink
+ NotFoundPage
Browse files Browse the repository at this point in the history
  • Loading branch information
Irina-anat committed Feb 24, 2024
1 parent b52f853 commit 18ad993
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Route, Routes } from "react-router-dom";
import { lazy } from "react";
import { Layout } from "./Layout/Layout";
import css from './App.module.css';
//import css from './App.module.css';
//import Home from "pages/Home/Home";
//import MovieDetails from "pages/MovieDetails/MovieDetails";
//import Movies from "pages/Movies/Movies";
Expand All @@ -18,6 +18,7 @@ const Cast = lazy(() =>
...module,
default: module.Cast,
})));
const NotFoundPage = lazy(()=> import("../pages/NotFound/NotFound"));


export const App = () => {
Expand All @@ -35,7 +36,8 @@ export const App = () => {
<Route path="reviews" element={<Reviews />} />
</Route>
</Route>
<Route path="*" element={<div><h1 className={css.not__found}>Ooooops, page not found</h1></div>} />
{/* <Route path="*" element={<div><h1 className={css.not__found}>Ooooops, page not found</h1></div>} /> */}
<Route path="*" element={<NotFoundPage/>} />
</Routes>
</div>
)
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Home/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ const Home = () => {
fetchTrendingMovies().then(response => setMovies(response))
}, []);

return <main className={css.container}>
return <div className={css.container}>
<h1 className={css.trending__title}>Trending today</h1>
<MoviesList movies={movies} />
</main>
</div>
};

export default Home;
Expand Down
4 changes: 2 additions & 2 deletions src/pages/MovieDetails/MovieDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const MovieDetails = () => {
}, [movieId]);

return (
<main className={css.movie__container}>
<div className={css.movie__container}>
<Link to={backLinkLocationRef.current}>
{' '}
<button type="button" aria-label="Go back to the previous page">Go back</button>
Expand Down Expand Up @@ -80,7 +80,7 @@ const MovieDetails = () => {
<Suspense fallback={<Loader/>}>
<Outlet />
</Suspense>
</main>
</div>
);
};

Expand Down
4 changes: 2 additions & 2 deletions src/pages/Movies/Movies.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ import css from './Movies.module.css';
}, [query]);

return (
<main className={css.container__search}>
<div className={css.container__search}>
<SearchForm location={location} onSubmit={handleSubmit} />
{movies.length > 0 && <MoviesList movies={movies} />}
</main>
</div>
);
};

Expand Down
25 changes: 25 additions & 0 deletions src/pages/NotFound/NotFound.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React, { useRef } from 'react';
import css from './NotFound.module.css';
import { Link, useLocation } from 'react-router-dom';

const NotFoundPage = () => {
const location = useLocation();
const backLinkLocationRef = useRef(location.state?.from ?? './movies');

return (
<div className={css.page}>
<div className={css.container}>
<h1 className={css.not__title}>404 Not Found</h1>
<p className={css.not__text}>
Oops! The page you are looking for might be in another castle.
</p>
<Link to={backLinkLocationRef.current}>
{' '}
<button type="button" aria-label="Go back to the previous page">Go to search</button>
</Link>
</div>
</div>
);
};

export default NotFoundPage;
26 changes: 26 additions & 0 deletions src/pages/NotFound/NotFound.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.page {
background-color: #f4f4f4;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}

.container {
text-align: center;
}

.not__title {
font-size: 3em;
color: #333;
margin-bottom: 20px;
}

.not__text {
font-size: 1.5em;
color: #555;
margin-bottom: 30px;
}


0 comments on commit 18ad993

Please sign in to comment.