File tree Expand file tree Collapse file tree 4 files changed +51
-0
lines changed
packages/next/src/views/Root Expand file tree Collapse file tree 4 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import React from 'react'
1717import { DefaultTemplate } from '../../templates/Default/index.js'
1818import { MinimalTemplate } from '../../templates/Minimal/index.js'
1919import { initPage } from '../../utilities/initPage/index.js'
20+ import { getCustomViewByRoute } from './getCustomViewByRoute.js'
2021import { getRouteData } from './getRouteData.js'
2122
2223export type GenerateViewMetadata = ( args : {
@@ -62,6 +63,32 @@ export const RootPage = async ({
6263
6364 const searchParams = await searchParamsPromise
6465
66+ // Redirect `${adminRoute}/collections` to `${adminRoute}`
67+ if ( segments . length === 1 && segments [ 0 ] === 'collections' ) {
68+ const { viewKey } = getCustomViewByRoute ( {
69+ config,
70+ currentRoute : '/collections' ,
71+ } )
72+
73+ // Only redirect if there's NO custom view configured for /collections
74+ if ( ! viewKey ) {
75+ redirect ( adminRoute )
76+ }
77+ }
78+
79+ // Redirect `${adminRoute}/globals` to `${adminRoute}`
80+ if ( segments . length === 1 && segments [ 0 ] === 'globals' ) {
81+ const { viewKey } = getCustomViewByRoute ( {
82+ config,
83+ currentRoute : '/globals' ,
84+ } )
85+
86+ // Only redirect if there's NO custom view configured for /globals
87+ if ( ! viewKey ) {
88+ redirect ( adminRoute )
89+ }
90+ }
91+
6592 const {
6693 browseByFolderSlugs,
6794 DefaultView,
Original file line number Diff line number Diff line change @@ -64,6 +64,13 @@ test.describe('Admin Panel (Root)', () => {
6464 // })
6565 // })
6666
67+ test ( 'should redirect `${adminRoute}/collections` to `${adminRoute}' , async ( ) => {
68+ const collectionsURL = `${ url . admin } /collections`
69+ await page . goto ( collectionsURL )
70+ // Should redirect to dashboard
71+ await expect . poll ( ( ) => page . url ( ) ) . toBe ( `${ url . admin } ` )
72+ } )
73+
6774 test ( 'renders admin panel at root' , async ( ) => {
6875 await page . goto ( url . admin )
6976 const pageURL = page . url ( )
Original file line number Diff line number Diff line change @@ -83,6 +83,10 @@ export default buildConfigWithDefaults({
8383 views : {
8484 // Dashboard: CustomDashboardView,
8585 // Account: CustomAccountView,
86+ collections : {
87+ Component : '/components/views/CustomView/index.js#CustomView' ,
88+ path : '/collections' ,
89+ } ,
8690 CustomDefaultView : {
8791 Component : '/components/views/CustomDefault/index.js#CustomDefaultView' ,
8892 path : '/custom-default-view' ,
Original file line number Diff line number Diff line change @@ -358,6 +358,19 @@ describe('General', () => {
358358 const response = await page . goto ( customLogoutRouteURL )
359359 expect ( response . status ( ) !== 404 ) . toBeTruthy ( )
360360 } )
361+
362+ test ( 'should not redirect `${adminRoute}/collections` to `${adminRoute} if there is a custom view' , async ( ) => {
363+ const collectionsURL = `${ serverURL } /admin/collections`
364+ await page . goto ( collectionsURL )
365+ await expect ( page . getByText ( 'Custom View' ) . first ( ) ) . toBeVisible ( )
366+ } )
367+
368+ test ( 'should redirect `${adminRoute}/globals` to `${adminRoute}' , async ( ) => {
369+ const globalsURL = `${ serverURL } /admin/globals`
370+ await page . goto ( globalsURL )
371+ // Should redirect to dashboard
372+ await expect . poll ( ( ) => page . url ( ) ) . toBe ( `${ serverURL } /admin` )
373+ } )
361374 } )
362375
363376 describe ( 'navigation' , ( ) => {
You can’t perform that action at this time.
0 commit comments