@@ -42,12 +42,29 @@ const App: React.FC = () => {
4242 const recordId = ':recordId'
4343 const pageName = ':pageName'
4444
45+ const dashboardUrl = h . dashboardUrl ( )
4546 const recordActionUrl = h . recordActionUrl ( { resourceId, recordId, actionName } )
4647 const resourceActionUrl = h . resourceActionUrl ( { resourceId, actionName } )
4748 const bulkActionUrl = h . bulkActionUrl ( { resourceId, actionName } )
4849 const resourceUrl = h . resourceUrl ( { resourceId } )
4950 const pageUrl = h . pageUrl ( pageName )
5051
52+ /**
53+ * When defining AdminJS routes, we use Routes component twice.
54+ * This results in warnings appearing in console, for example about not being able to locate
55+ * "/admin" route. They can be safely ignored though and should appear only
56+ * in development environment. The warnings originate from the difference between
57+ * "Switch" component that AdminJS had used in "react-router" v5 which was later replaced
58+ * with "Routes" in "react-router" v6. "Switch" would use the first "Route" component
59+ * that matched the provided path, while "Routes" searches for the best matching pattern.
60+ * In AdminJS we use "DrawerPortal" to display actions in a drawer when
61+ * "showInDrawer" option is set to true. The drawer should appear above the currently viewed
62+ * page, but "Routes" broke this behavior because it instead showed a record action route with
63+ * an empty background.
64+ * The current flow is that first "Routes" component includes "Resource" route component
65+ * for drawer-placed actions and the second "Routes" is entered for record actions
66+ * on a separate page.
67+ */
5168 return (
5269 < >
5370 < Reset />
@@ -60,17 +77,19 @@ const App: React.FC = () => {
6077 ) : null }
6178 < Sidebar isVisible = { sidebarVisible } />
6279 < Box flex flexGrow = { 1 } flexDirection = "column" overflowY = "auto" bg = "bg" >
63- < TopBar toggleSidebar = { ( ) : void => toggleSidebar ( ! sidebarVisible ) } />
80+ < TopBar toggleSidebar = { ( ) => toggleSidebar ( ! sidebarVisible ) } />
6481 < Box position = "absolute" top = { 0 } zIndex = { 2000 } >
6582 < Notice />
6683 </ Box >
6784 < Routes >
68- < Route path = { h . dashboardUrl ( ) } element = { < Dashboard /> } />
6985 < Route path = { `${ resourceUrl } /*` } element = { < Resource /> } />
7086 < Route path = { pageUrl } element = { < Page /> } />
71- < Route path = { `${ recordActionUrl } /*` } element = { < RecordAction /> } />
87+ < Route path = { dashboardUrl } element = { < Dashboard /> } />
88+ </ Routes >
89+ < Routes >
7290 < Route path = { `${ resourceActionUrl } /*` } element = { < ResourceAction /> } />
7391 < Route path = { `${ bulkActionUrl } /*` } element = { < BulkAction /> } />
92+ < Route path = { `${ recordActionUrl } /*` } element = { < RecordAction /> } />
7493 </ Routes >
7594 </ Box >
7695 </ Box >
0 commit comments