Skip to content

Commit

Permalink
feat: 404 for unknown pages
Browse files Browse the repository at this point in the history
  • Loading branch information
jmlweb committed Jul 27, 2023
1 parent e9c8098 commit 52fe0de
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Metadata, ResolvingMetadata } from 'next';
import { notFound } from 'next/navigation';

import { Container } from '@/components/Container';
import { ItemsGrid } from '@/components/ItemsGrid';
Expand Down Expand Up @@ -30,6 +31,9 @@ export const generateMetadata = async (
const data = await dataService.findBeaches(Number(currentPage), (beach) =>
beach.features.includes(slug),
);
if (!data.beaches.length) {
notFound();
}
const previousImages = (await parent).openGraph?.images || [];
const selectedBeach = data.beaches.find((beach) => beach.picture);
const selectedImage = selectedBeach
Expand Down
4 changes: 4 additions & 0 deletions apps/web/src/app/lista-playas/[[...currentPage]]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Metadata, ResolvingMetadata } from 'next';
import { notFound } from 'next/navigation';

import { Container } from '@/components/Container';
import { ItemsGrid } from '@/components/ItemsGrid';
Expand All @@ -22,6 +23,9 @@ export const generateMetadata = async (
parent: ResolvingMetadata,
): Promise<Metadata> => {
const data = await dataService.findBeaches(Number(currentPage));
if (!data.beaches.length) {
notFound();
}
const previousImages = (await parent).openGraph?.images || [];
const selectedBeach = data.beaches.find((beach) => beach.picture);
const selectedImage = selectedBeach
Expand Down
5 changes: 5 additions & 0 deletions apps/web/src/app/municipio/[slug]/[[...currentPage]]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Metadata, ResolvingMetadata } from 'next';
import { notFound } from 'next/navigation';

import { Container } from '@/components/Container';
import { ItemsGrid } from '@/components/ItemsGrid';
Expand Down Expand Up @@ -58,6 +59,10 @@ const Municipality = async ({
(beach) => beach.municipality === slug,
);

if (!data.beaches.length) {
notFound();
}

return (
<Container fixed>
<ItemsSectionHeader
Expand Down

0 comments on commit 52fe0de

Please sign in to comment.