diff --git a/apps/cow-fi/app/(learn)/learn/articles/[[...pageIndex]]/page.tsx b/apps/cow-fi/app/(learn)/learn/articles/[[...pageIndex]]/page.tsx index 590c10c700..f048215b23 100644 --- a/apps/cow-fi/app/(learn)/learn/articles/[[...pageIndex]]/page.tsx +++ b/apps/cow-fi/app/(learn)/learn/articles/[[...pageIndex]]/page.tsx @@ -2,6 +2,7 @@ import { Article, getArticles, getCategories } from '../../../../../services/cms' import { ArticlesPageComponents } from '@/components/ArticlesPageComponents' +import { redirect } from 'next/navigation' const ITEMS_PER_PAGE = 24 @@ -28,7 +29,14 @@ export async function generateStaticParams() { export default async function Page({ params }: Props) { const pageParam = (await params)?.pageIndex - const page = pageParam && pageParam.length > 0 ? parseInt(pageParam[0], 10) : 1 + const paramsAreSet = Boolean(pageParam && pageParam.length > 0) + const pageIndexIsValid = Boolean(pageParam && /^\d+$/.test(pageParam)) + + if (paramsAreSet && !pageIndexIsValid) { + return redirect('/learn/articles') + } + + const page = pageParam && pageIndexIsValid ? parseInt(pageParam, 10) : 1 const articlesResponse = (await getArticles({ page, pageSize: ITEMS_PER_PAGE })) as ArticlesResponse diff --git a/apps/cow-fi/app/(main)/tokens/[tokenId]/page.tsx b/apps/cow-fi/app/(main)/tokens/[tokenId]/page.tsx index f52dbd237e..56aeeb9478 100644 --- a/apps/cow-fi/app/(main)/tokens/[tokenId]/page.tsx +++ b/apps/cow-fi/app/(main)/tokens/[tokenId]/page.tsx @@ -9,6 +9,7 @@ import { TokenPageComponent } from '@/components/TokenPageComponent' import type { Metadata } from 'next' import type { TokenDetails } from '../../../../types' import { getPageMetadata } from '@/util/getPageMetadata' +import { redirect } from 'next/navigation' type Props = { params: Promise<{ tokenId: string }> @@ -35,6 +36,8 @@ export async function generateMetadata({ params }: Props): Promise { const token = await getTokenDetails(tokenId) + if (!token) return {} + return getPageMetadata(getTokenMetaData(token)) } @@ -51,5 +54,7 @@ export default async function Page({ params }: Props) { const token = await getTokenDetails(tokenId) + if (!token) return redirect('/tokens') + return } diff --git a/apps/cow-fi/services/tokens/index.ts b/apps/cow-fi/services/tokens/index.ts index c2cee43198..fa00faf495 100644 --- a/apps/cow-fi/services/tokens/index.ts +++ b/apps/cow-fi/services/tokens/index.ts @@ -48,10 +48,10 @@ export async function getTokensInfo(): Promise { * * @returns token details for the given token id */ -export async function getTokenDetails(coingeckoId: string): Promise { +export async function getTokenDetails(coingeckoId: string): Promise { const id = coingeckoId.toLowerCase() const tokensRaw = await _getAllTokensData() - return tokensRaw.find(({ id: _id }) => _id === id) as TokenDetails + return tokensRaw.find(({ id: _id }) => _id === id) as TokenDetails | undefined } function _getDescriptionFilePaths(): string[] {