Skip to content

Commit

Permalink
add useNavigate to home if movie id is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
konstantin-it-lysenko committed Dec 21, 2023
1 parent ef18c0f commit 7930fef
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/pages/MovieDetails.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import { CastReviewLink, CastReviewsList } from 'components/App/App.styled';
import Movie from 'components/Movie/Movie';
import { Suspense, useEffect, useRef, useState } from 'react';
import { Link, Outlet, useLocation, useParams } from 'react-router-dom';
import {
Link,
Outlet,
useLocation,
useNavigate,
useParams,
} from 'react-router-dom';
import { getMovieById } from 'service/getMovies';

const MovieDetails = () => {
const { movieId } = useParams();
const [movie, setMovie] = useState(null);

const navigate = useNavigate();
const location = useLocation();
const backLinkRef = useRef(location.state?.from ?? '/');

Expand All @@ -23,6 +30,7 @@ const MovieDetails = () => {
setMovie(response);
} catch (err) {
console.error(err);
navigate('/');
}
};

Expand Down

0 comments on commit 7930fef

Please sign in to comment.