Added pet-not-found

This commit is contained in:
Dino Tutic 2023-07-16 21:04:31 +02:00
parent 8485efc47c
commit 786efc86fd
4 changed files with 15 additions and 9 deletions

View File

@ -20,6 +20,7 @@ const appRouter = createBrowserRouter(
<Route path=":type" element={<HomePage />} /> <Route path=":type" element={<HomePage />} />
<Route path=":type/:id" element={<PetDetailsPage />} /> <Route path=":type/:id" element={<PetDetailsPage />} />
<Route path="search" element={<SearchPage />} /> <Route path="search" element={<SearchPage />} />
<Route path="pet-details-not-found" element={<PetDetailsNotFound />} />
</Route> </Route>
) )
); );

View File

@ -20,6 +20,8 @@ const Search = () => {
const query = createSearchParams(searchQuery); const query = createSearchParams(searchQuery);
// imperatively redirect with useNavigate() returned function // imperatively redirect with useNavigate() returned function
//Dont really understand why I am passing an object to useNavigate
navigate({ pathname: "/search", search: `${query}` }); navigate({ pathname: "/search", search: `${query}` });
}; };

View File

@ -2,6 +2,7 @@ import React, { useEffect, useState } from "react";
import { getPetDetails } from "../../api/petfinder"; import { getPetDetails } from "../../api/petfinder";
import Hero from "../../components/hero"; import Hero from "../../components/hero";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import { Navigate } from "react-router-dom";
// Import useParams // Import useParams
// Import Navigate // Import Navigate
@ -33,7 +34,7 @@ const PetDetailsPage = () => {
<h3>Loading...</h3> <h3>Loading...</h3>
) : error ? ( ) : error ? (
<div> <div>
{/* Redirect to /pet-details-not-found if there was an error! */} <Navigate to="/pet-details-not-found" />
</div> </div>
) : ( ) : (
<main> <main>

View File

@ -1,19 +1,21 @@
import React from 'react'; import React from "react";
// import useNavigate here. import { useNavigate } from "react-router-dom";
const PetDetailsNotFound = () => { const PetDetailsNotFound = () => {
// get the navigate function from useNavigate // get the navigate function from useNavigate
const navigate = "REPLACE ME"; const navigate = useNavigate();
const goHome = () => { const goHome = () => {
// Go home! navigate("/");
} };
return ( return (
<main className="page"> <main className="page">
<h3>404: Who let the dogs out?</h3> <h3>404: Who let the dogs out?</h3>
<p>Sorry, but the details for this pet have not been uploaded by the shelter yet. Check back later!</p> <p>
Sorry, but the details for this pet have not been uploaded by the
shelter yet. Check back later!
</p>
<img <img
src="https://i.chzbgr.com/full/8362031616/h9EB970C5/weve-lost-our-corgination" src="https://i.chzbgr.com/full/8362031616/h9EB970C5/weve-lost-our-corgination"
alt="" alt=""