@@ -42,12 +42,29 @@ const App: React.FC = () => {
42
42
const recordId = ':recordId'
43
43
const pageName = ':pageName'
44
44
45
+ const dashboardUrl = h . dashboardUrl ( )
45
46
const recordActionUrl = h . recordActionUrl ( { resourceId, recordId, actionName } )
46
47
const resourceActionUrl = h . resourceActionUrl ( { resourceId, actionName } )
47
48
const bulkActionUrl = h . bulkActionUrl ( { resourceId, actionName } )
48
49
const resourceUrl = h . resourceUrl ( { resourceId } )
49
50
const pageUrl = h . pageUrl ( pageName )
50
51
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
+ */
51
68
return (
52
69
< >
53
70
< Reset />
@@ -60,17 +77,19 @@ const App: React.FC = () => {
60
77
) : null }
61
78
< Sidebar isVisible = { sidebarVisible } />
62
79
< Box flex flexGrow = { 1 } flexDirection = "column" overflowY = "auto" bg = "bg" >
63
- < TopBar toggleSidebar = { ( ) : void => toggleSidebar ( ! sidebarVisible ) } />
80
+ < TopBar toggleSidebar = { ( ) => toggleSidebar ( ! sidebarVisible ) } />
64
81
< Box position = "absolute" top = { 0 } zIndex = { 2000 } >
65
82
< Notice />
66
83
</ Box >
67
84
< Routes >
68
- < Route path = { h . dashboardUrl ( ) } element = { < Dashboard /> } />
69
85
< Route path = { `${ resourceUrl } /*` } element = { < Resource /> } />
70
86
< Route path = { pageUrl } element = { < Page /> } />
71
- < Route path = { `${ recordActionUrl } /*` } element = { < RecordAction /> } />
87
+ < Route path = { dashboardUrl } element = { < Dashboard /> } />
88
+ </ Routes >
89
+ < Routes >
72
90
< Route path = { `${ resourceActionUrl } /*` } element = { < ResourceAction /> } />
73
91
< Route path = { `${ bulkActionUrl } /*` } element = { < BulkAction /> } />
92
+ < Route path = { `${ recordActionUrl } /*` } element = { < RecordAction /> } />
74
93
</ Routes >
75
94
</ Box >
76
95
</ Box >
0 commit comments