Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for catchall with new router #38439

Merged
merged 4 commits into from
Jul 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions packages/next/server/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,24 @@ export async function renderToHTML(
// TODO: use correct matching for dynamic routes to get segment param
const segmentParam =
segment.startsWith('[') && segment.endsWith(']')
? segment.slice(1, -1)
? segment.slice(segment.startsWith('[...') ? 4 : 1, -1)
: null

if (!segmentParam || !pathParams[segmentParam]) {
if (!segmentParam || (!pathParams[segmentParam] && !query[segmentParam])) {
return null
}

// @ts-expect-error TODO: handle case where value is an array
return { param: segmentParam, value: pathParams[segmentParam] }
return {
param: segmentParam,
// @ts-expect-error TODO: handle case where value is an array
value:
// TODO: this should only read from `pathParams`. There's an inconsistency where `query` holds params currently which has to be fixed.
pathParams[segmentParam] ??
(Array.isArray(query[segmentParam])
? // @ts-expect-error TODO: handle case where value is an array
query[segmentParam].join('/')
: query[segmentParam]),
}
}

const createFlightRouterStateFromLoaderTree = ([
Expand Down Expand Up @@ -546,10 +555,9 @@ export async function renderToHTML(
| GetServerSidePropsContext
| getServerSidePropsContextPage = {
headers,
// TODO: convert to NextCookies
cookies,
layoutSegments: segmentPath,
// TODO: change this to be URLSearchParams instead?
// TODO: Currently query holds params and pathname is not the actual pathname, it holds the dynamic parameter
...(isPage ? { query, pathname } : {}),
...(pageIsDynamic ? { params: currentParams } : undefined),
...(isPreview
Expand Down