Skip to content

Commit 11d76cf

Browse files
committed
Optional route params
1 parent 14d49ae commit 11d76cf

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

frontends/main/src/app/search/page.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
import React from "react"
22
import { getMetadataAsync } from "@/common/metadata"
33
import SearchPage from "@/app-pages/SearchPage/SearchPage"
4+
import type { PageParams } from "@/app/types"
45

5-
type SearchParams = {
6-
[key: string]: string | string[] | undefined
7-
}
8-
9-
export async function generateMetadata({
10-
searchParams,
11-
}: {
12-
searchParams: Promise<SearchParams>
13-
}) {
6+
export async function generateMetadata({ searchParams }: PageParams) {
147
return await getMetadataAsync({
158
title: "Search",
169
searchParams,
@@ -29,7 +22,8 @@ export async function generateMetadata({
2922
*/
3023
export const dynamic = "force-dynamic"
3124

32-
const Page: React.FC = () => {
25+
const Page: React.FC = ({ searchParams }: PageParams) => {
26+
console.log("searchParams", searchParams)
3327
return <SearchPage />
3428
}
3529

frontends/main/src/app/types.d.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ export type SearchParams = {
22
[key: string]: string | string[] | undefined
33
}
44

5-
export type PageParams<RouteParams = Record<string, never>> = {
6-
params?: Promise<RouteParams>
5+
type PageParamsWithRouteParams<RouteParams> = {
6+
params: Promise<RouteParams>
77
searchParams?: Promise<SearchParams>
88
}
9+
10+
type PageParamsWithoutRouteParams = {
11+
searchParams?: Promise<SearchParams>
12+
}
13+
14+
export type PageParams<RouteParams = Record<string, never>> =
15+
RouteParams extends Record<string, never>
16+
? PageParamsWithoutRoute
17+
: PageParamsWithRoute<RouteParams>

0 commit comments

Comments
 (0)