You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Site Editor and Admin Redesign: Build a solid routing foundation. #60584
[Feature] Navigation in Site ViewNavigation section in the Site Editor when in Site View, offering a way to manage Navigation Menus a[Type] Tracking IssueTactical breakdown of efforts across the codebase and/or tied to Overview issues.
The site editor has a built-in routing approach that is a bit fragile and hard to scale to the next steps of the Admin Redesign project. It is time to look at it and refactor it to both address its immediate shortcomings (bugs and maintainability) and provide a solid base for the next steps (extensibility, new pages)...
The solution needs to address the following requirements:
Creating and maintaining routes today is not easy at all. You have to include code in very different places (sidebar routing, multiple sync hooks, and router.js file), we should have a coherent way to define routes.
There's a lot of bugs when navigating in the site editor due to lingering arguments in the url... Having a consistent API for routing and links will help us address these bugs holistically
Ultimately, we'd like to split the "routing/shell" of the site editor from its content (the different routes) in order to be able to build multiple site editor like experiences.
We'd like a simple routing API that we can open later for third-parties (probably starting as a private API as we work through things)
Reacted by Damon Cook and Fabian Kägy
Reacted by Daniel Richards, Fabian Kägy and annezazu
I believed #60466 by @jsnajdr solved most of the big issues we had in terms of maintainability, it's also a path forward towards decoupling the layout from the pages. I believe we can probably start experimenting (and using) with a private API to register routes (replace the router.js file with it).
One thing that's currently odd about the site-editor.php router is that the routes are not really routes, but just query params. Sometimes there is a path param, but it's not mandatory. For example, the post edit page has just postType and postId and no path.
In a mainstream router, this would all be just one site-editor.php route with various query parameters.
One prior art that comes to mind is the WordPress REST API. You can use the raw, not-pretty URL where you refer to a PHP file and pass all information in query params:
But the preferred choice is to have a pretty URL where the rest_route is really a part of the path:
/wp-json/wp/v2/categories?per_page=100&order=asc
I guess that eventually we want to have also wp-admin pretty URLs like this? For example, instead of
/wp-admin/site-editor.php?path=/page&postId=1
there would be this in the URL bar:
/wp-admin/site-editor/page/1
I think that's feasible and worth exploring. One additional question: do we already have other wp-admin use cases, other than Site Editor, where we should explore routing? Like, for example, a DataView enabled Posts page?
My current plan for routing is:
wrap up the Navigator refactoring by putting backPath links everywhere and abandoning the getBackPath/goToParent methods. It's a heuristic that works in one particular case, but is not universally applicable. It's not always true that the proper back path for /foo/bar/baz is /foo/bar, i.e., removing the last / suffix.
remove the Navigator/useSyncPathWithURL logic also from Woo's Customize Store UI. Turns out they have a copy&paste of the Site Editor code 🤦
start these pretty-path explorations, and make further steps towards a respectable @wordpress/router package.
Actually, I think this is one of the next steps that I want to explore. I didn't track this yet but I do want to see whether we can build a "site editor" like experience for posts/categories to replace the "edit.php" we have right now. Should be an experiment first but I was kind of waiting for the routing work to advance a bit to start on that part.
From the URL, it determines what should be displayed in the content area. We should move this code to the router's useLayoutAreas hook, just like we moved the sidebars. useLayoutAreas currently declares a constant, non-specific preview: <Editor> for all routes.
@jsnajdr I agree, I think the ideal would be to have postType, postId and context as props to the Editor component. The problem though is that we still need to keep the state in the edit-site store for backward compatibility. So we'll have to update the state (maybe as an effect in the Editor component or something).
Hi, y'all, will it be possible to hook into the single post route to provide a custom React-based editing experience rather than the Block Editor? (And is this the right place for this question?)
@dannyreaktiv That means that you want to completely disable Gutenberg and replace the post editor with your own custom app? In that case you don't want to hook into anything in the Gutenberg codebase, but do it directly at the WordPress level. The Classic Editor plugin could be an inspiration for this.
If the post tables are being replaced with DataViews, it would be nice to hook into edit post action to launch a custom view (such as a modal) rather than redirect to the editor.
I've just opened #70862 where I'm defining the requirements for the routing and layout API that we need for the admin redesign based on all the learnings so far. Feedback appreciated. I'm going to close the current issue for now.
[Feature] Navigation in Site ViewNavigation section in the Site Editor when in Site View, offering a way to manage Navigation Menus a[Type] Tracking IssueTactical breakdown of efforts across the codebase and/or tied to Overview issues.
Activity
youknowriad commentedon Apr 25, 2024
I believed #60466 by @jsnajdr solved most of the big issues we had in terms of maintainability, it's also a path forward towards decoupling the layout from the pages. I believe we can probably start experimenting (and using) with a private API to register routes (replace the router.js file with it).
jsnajdr commentedon Apr 25, 2024
One thing that's currently odd about the
site-editor.phprouter is that the routes are not really routes, but just query params. Sometimes there is apathparam, but it's not mandatory. For example, the post edit page has justpostTypeandpostIdand nopath.In a mainstream router, this would all be just one
site-editor.phproute with various query parameters.youknowriad commentedon Apr 25, 2024
@jsnajdr do you think we should explore pretty permalinks to improve that? I guess it still needs to land on site-editor.php anyway
jsnajdr commentedon Apr 26, 2024
One prior art that comes to mind is the WordPress REST API. You can use the raw, not-pretty URL where you refer to a PHP file and pass all information in query params:
But the preferred choice is to have a pretty URL where the
rest_routeis really a part of the path:I guess that eventually we want to have also
wp-adminpretty URLs like this? For example, instead ofthere would be this in the URL bar:
I think that's feasible and worth exploring. One additional question: do we already have other
wp-adminuse cases, other than Site Editor, where we should explore routing? Like, for example, aDataViewenabled Posts page?My current plan for routing is:
Navigatorrefactoring by puttingbackPathlinks everywhere and abandoning thegetBackPath/goToParentmethods. It's a heuristic that works in one particular case, but is not universally applicable. It's not always true that the proper back path for/foo/bar/bazis/foo/bar, i.e., removing the last/suffix.Navigator/useSyncPathWithURLlogic also from Woo's Customize Store UI. Turns out they have a copy&paste of the Site Editor code 🤦@wordpress/routerpackage.youknowriad commentedon Apr 26, 2024
Actually, I think this is one of the next steps that I want to explore. I didn't track this yet but I do want to see whether we can build a "site editor" like experience for posts/categories to replace the "edit.php" we have right now. Should be an experiment first but I was kind of waiting for the routing work to advance a bit to start on that part.
Sounds good to me.
jsnajdr commentedon Apr 30, 2024
This code in
useInitEditedEntityFromURLis also very suboptimal:gutenberg/packages/edit-site/src/components/sync-state-with-url/use-init-edited-entity-from-url.js
Lines 204 to 246 in 77f03d3
From the URL, it determines what should be displayed in the content area. We should move this code to the router's
useLayoutAreashook, just like we moved the sidebars.useLayoutAreascurrently declares a constant, non-specificpreview: <Editor>for all routes.youknowriad commentedon Apr 30, 2024
@jsnajdr I agree, I think the ideal would be to have postType, postId and context as props to the
Editorcomponent. The problem though is that we still need to keep the state in the edit-site store for backward compatibility. So we'll have to update the state (maybe as an effect in the Editor component or something).dannyreaktiv commentedon Jun 14, 2024
Hi, y'all, will it be possible to hook into the single post route to provide a custom React-based editing experience rather than the Block Editor? (And is this the right place for this question?)
jsnajdr commentedon Jun 15, 2024
@dannyreaktiv That means that you want to completely disable Gutenberg and replace the post editor with your own custom app? In that case you don't want to hook into anything in the Gutenberg codebase, but do it directly at the WordPress level. The Classic Editor plugin could be an inspiration for this.
dannyreaktiv commentedon Jun 15, 2024
@jsnajdr Thanks for replying.
If the post tables are being replaced with DataViews, it would be nice to hook into edit post action to launch a custom view (such as a modal) rather than redirect to the editor.
youknowriad commentedon Jul 23, 2025
I've just opened #70862 where I'm defining the requirements for the routing and layout API that we need for the admin redesign based on all the learnings so far. Feedback appreciated. I'm going to close the current issue for now.