Skip to content

Commit 1461b9c

Browse files
committed
not found pages
1 parent 4d5ad6d commit 1461b9c

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

app/components/CountryCard.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Country } from "../types";
33

44
const CountryCard = ({ country }: { country: Country }) => {
55
return (
6-
<Link href={`/${country.cca3}`}>
6+
<Link href={`/country/${country.cca3}`}>
77
<article className="p-5 rounded-lg shadow-sm bg-white dark:bg-gray-700 space-y-7 border border-gray-300/50 dark:border-gray-500/50 md:hover:scale-[104%] transition-transform">
88
<div className="aspect-video">
99
<img

app/country/[cca3]/not-found.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import BackButton from "@/app/components/shared/BackButton";
2+
3+
const NotFound = () => {
4+
return (
5+
<div className="px-4 md:container mt-10 space-y-10">
6+
<BackButton />
7+
<p>Country not found</p>
8+
</div>
9+
);
10+
};
11+
12+
export default NotFound;

app/[cca3]/page.tsx app/country/[cca3]/page.tsx

+3-11
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,13 @@ import Link from "next/link";
44
import { Button } from "@/components/ui/button";
55
import { Country } from "@/app/types";
66
import BackButton from "@/app/components/shared/BackButton";
7+
import { notFound } from "next/navigation";
78

89
const CountryPage = async ({ params }: { params: { cca3: string } }) => {
9-
const { data, error } = await getCountry(params.cca3);
10+
const { data } = await getCountry(params.cca3);
1011
const country = data as Country;
1112

12-
if (error) {
13-
return (
14-
<div className="container">
15-
<div className="my-10">
16-
<BackButton />
17-
</div>
18-
<p>{error}</p>
19-
</div>
20-
);
21-
}
13+
if (!country) notFound()
2214

2315
const nativeName = country.name.nativeName
2416
? Object.values(country.name.nativeName)[0]

app/not-found.tsx

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import BackButton from "./components/shared/BackButton";
2+
3+
const NotFound = () => {
4+
return (
5+
<div className="px-4 md:container mt-10 space-y-10">
6+
<BackButton />
7+
<p>Page not found</p>
8+
</div>
9+
);
10+
};
11+
12+
export default NotFound;

0 commit comments

Comments
 (0)