Skip to content

fix: adds routeParams to the req on views #12711

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

Merged
merged 3 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/next/src/utilities/initPage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const initPage = async ({
config: configPromise,
importMap,
route,
routeParams = {},
searchParams,
useLayoutReq,
}: Args): Promise<InitPageResult> => {
Expand All @@ -38,6 +39,7 @@ export const initPage = async ({
depth: 10,
ignoreQueryPrefix: true,
}),
routeParams,
},
urlSuffix: `${route}${searchParams ? queryString : ''}`,
},
Expand Down
6 changes: 6 additions & 0 deletions packages/next/src/utilities/initPage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export type Args = {
* The current route, i.e. `/admin/collections/posts`.
*/
route: string
/**
* The route parameters of the current route
*
* @example `{ collection: 'posts', id: "post-id" }`.
*/
routeParams?: { [key: string]: string }
/**
* The search parameters of the current route provided to all pages in Next.js.
*/
Expand Down
16 changes: 16 additions & 0 deletions packages/next/src/views/Root/getRouteData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export const getRouteData = ({
config,
importMap,
route: currentRoute,
routeParams: {},
searchParams,
}

Expand Down Expand Up @@ -212,6 +213,8 @@ export const getRouteData = ({
`/${segmentOne}` === config.admin.routes.browseByFolder
) {
// --> /browse-by-folder/:folderID
initPageOptions.routeParams.folderID = folderID

ViewToRender = {
Component: oneSegmentViews.browseByFolder,
}
Expand All @@ -221,6 +224,7 @@ export const getRouteData = ({
folderID = segmentTwo
} else if (isCollection && matchedCollection) {
// --> /collections/:collectionSlug
initPageOptions.routeParams.collection = matchedCollection.slug

ViewToRender = {
Component: ListView,
Expand All @@ -234,6 +238,7 @@ export const getRouteData = ({
)
} else if (isGlobal && matchedGlobal) {
// --> /globals/:globalSlug
initPageOptions.routeParams.global = matchedGlobal.slug

ViewToRender = {
Component: DocumentView,
Expand All @@ -256,6 +261,8 @@ export const getRouteData = ({
default:
if (segmentTwo === 'verify') {
// --> /:collectionSlug/verify/:token
initPageOptions.routeParams.collection = segmentOne

ViewToRender = {
Component: Verify,
}
Expand All @@ -264,10 +271,14 @@ export const getRouteData = ({
templateType = 'minimal'
viewType = 'verify'
} else if (isCollection && matchedCollection) {
initPageOptions.routeParams.collection = matchedCollection.slug
if (config.folders && segmentThree === config.folders.slug && matchedCollection.folders) {
// Collection Folder Views
// --> /collections/:collectionSlug/:folderCollectionSlug
// --> /collections/:collectionSlug/:folderCollectionSlug/:folderID
initPageOptions.routeParams.folderCollection = segmentThree
initPageOptions.routeParams.folderID = segmentFour

ViewToRender = {
Component: CollectionFolderView,
}
Expand All @@ -283,6 +294,9 @@ export const getRouteData = ({
// --> /collections/:collectionSlug/:id/preview
// --> /collections/:collectionSlug/:id/versions
// --> /collections/:collectionSlug/:id/versions/:versionID
initPageOptions.routeParams.id = segmentThree
initPageOptions.routeParams.versionID = segmentFive

ViewToRender = {
Component: DocumentView,
}
Expand All @@ -306,6 +320,8 @@ export const getRouteData = ({
// --> /globals/:globalSlug/preview
// --> /globals/:globalSlug/versions/:versionID
// --> /globals/:globalSlug/api
initPageOptions.routeParams.global = matchedGlobal.slug
initPageOptions.routeParams.versionID = segmentFour

ViewToRender = {
Component: DocumentView,
Expand Down
Loading