diff --git a/packages/edit-site/src/components/layout/router.js b/packages/edit-site/src/components/layout/router.js index 20d5b463852ff3..8d9e14db92a9fa 100644 --- a/packages/edit-site/src/components/layout/router.js +++ b/packages/edit-site/src/components/layout/router.js @@ -3,7 +3,7 @@ */ import { privateApis as routerPrivateApis } from '@wordpress/router'; import { __ } from '@wordpress/i18n'; - +import { useEffect } from '@wordpress/element'; /** * Internal dependencies */ @@ -33,6 +33,14 @@ export default function useLayoutAreas() { const { params } = useLocation(); const { postType, postId, path, layout, isCustom, canvas } = params; + useEffect( () => { + // `/wp_template_part/all` path is no longer used and redirects to + // Patterns page for backward compatibility. + if ( path === '/wp_template_part/all' ) { + history.replace( { path: '/patterns' } ); + } + }, [ history, path ] ); + // Note: Since "sidebar" is not yet supported here, // returning undefined from "mobile" means show the sidebar. @@ -140,10 +148,9 @@ export default function useLayoutAreas() { }; } - /* Patterns and Template Parts - * `/wp_template_part/all` path is no longer used, but uses Patterns page screens for - * backwards compatibility. - */ + // Patterns + // `/wp_template_part/all` path is no longer used and redirects to + // Patterns page for backward compatibility. if ( path === '/patterns' || path === '/wp_template_part/all' ) { return { key: 'patterns', diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-patterns/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-patterns/index.js index ee01a427e6dc91..9c8681b86dbf37 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-patterns/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-patterns/index.js @@ -125,18 +125,6 @@ export default function SidebarNavigationScreenPatterns( { backPath } ) { [] ); - /** - * This sidebar needs to temporarily accomodate two different "URLs": - * - * 1. path = /patterns - * Block based themes. Also classic themes can access this URL, though it's not linked anywhere. - * - * 2. path = /wp_template_part/all - * Classic themes with support for block-template-parts. We need to list only Template Parts in this case. - * The URL is accessible from the Appearance > Template Parts menu. - * - * This is temporary. We aim to consolidate to /patterns. - */ return ( { ).toBeVisible(); } ); - test( 'should show Patterns page when accessing template parts list page', async ( { + test( 'should redirect to Patterns page when accessing template parts list page', async ( { admin, page, } ) => { @@ -32,6 +32,10 @@ test.describe( 'Hybrid theme', () => { 'path=/wp_template_part/all' ); + await expect( page ).toHaveURL( + '/wp-admin/site-editor.php?path=%2Fpatterns' + ); + await expect( page.getByRole( 'heading', { level: 1, text: 'Patterns' } ) ).toBeVisible();