-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4834 from grhallenbeck/dev-react-router
Migrate React Router to React Data Router pattern
- Loading branch information
Showing
17 changed files
with
347 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
|
||
import { History } from '@remix-run/router'; | ||
import React from 'react'; | ||
import { | ||
RouterProvider, | ||
createHashRouter, | ||
Outlet | ||
} from 'react-router-dom'; | ||
|
||
import { EXPERIMENTAL_APP_ROUTES } from 'apps/experimental/routes/routes'; | ||
import AppHeader from 'components/AppHeader'; | ||
import Backdrop from 'components/Backdrop'; | ||
import { useLegacyRouterSync } from 'hooks/useLegacyRouterSync'; | ||
import { DASHBOARD_APP_ROUTES } from 'apps/dashboard/routes/routes'; | ||
|
||
const router = createHashRouter([ | ||
{ | ||
element: <RootAppLayout />, | ||
children: [ | ||
...EXPERIMENTAL_APP_ROUTES, | ||
...DASHBOARD_APP_ROUTES | ||
] | ||
} | ||
]); | ||
|
||
export default function RootAppRouter({ history }: Readonly<{ history: History}>) { | ||
useLegacyRouterSync({ router, history }); | ||
|
||
return <RouterProvider router={router} />; | ||
} | ||
|
||
function RootAppLayout() { | ||
return ( | ||
<> | ||
<Backdrop /> | ||
<AppHeader isHidden /> | ||
|
||
<Outlet /> | ||
</> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import type { AsyncRoute } from 'components/router/AsyncRoute'; | ||
import { AsyncRouteType, type AsyncRoute } from 'components/router/AsyncRoute'; | ||
|
||
export const ASYNC_ADMIN_ROUTES: AsyncRoute[] = [ | ||
{ path: 'activity' }, | ||
{ path: 'notifications' }, | ||
{ path: 'users' }, | ||
{ path: 'users/access' }, | ||
{ path: 'users/add' }, | ||
{ path: 'users/parentalcontrol' }, | ||
{ path: 'users/password' }, | ||
{ path: 'users/profile' } | ||
{ path: 'activity', type: AsyncRouteType.Dashboard }, | ||
{ path: 'notifications', type: AsyncRouteType.Dashboard }, | ||
{ path: 'users', type: AsyncRouteType.Dashboard }, | ||
{ path: 'users/access', type: AsyncRouteType.Dashboard }, | ||
{ path: 'users/add', type: AsyncRouteType.Dashboard }, | ||
{ path: 'users/parentalcontrol', type: AsyncRouteType.Dashboard }, | ||
{ path: 'users/password', type: AsyncRouteType.Dashboard }, | ||
{ path: 'users/profile', type: AsyncRouteType.Dashboard } | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React from 'react'; | ||
import { RouteObject } from 'react-router-dom'; | ||
import AppLayout from '../AppLayout'; | ||
import ConnectionRequired from 'components/ConnectionRequired'; | ||
import { ASYNC_ADMIN_ROUTES } from './_asyncRoutes'; | ||
import { toAsyncPageRoute } from 'components/router/AsyncRoute'; | ||
import { toViewManagerPageRoute } from 'components/router/LegacyRoute'; | ||
import { LEGACY_ADMIN_ROUTES } from './_legacyRoutes'; | ||
import ServerContentPage from 'components/ServerContentPage'; | ||
|
||
export const DASHBOARD_APP_PATHS = { | ||
Dashboard: 'dashboard', | ||
MetadataManager: 'metadata', | ||
PluginConfig: 'configurationpage' | ||
}; | ||
|
||
export const DASHBOARD_APP_ROUTES: RouteObject[] = [ | ||
{ | ||
element: <ConnectionRequired isAdminRequired />, | ||
children: [ | ||
{ | ||
element: <AppLayout drawerlessPaths={[ DASHBOARD_APP_PATHS.MetadataManager ]} />, | ||
children: [ | ||
{ | ||
path: DASHBOARD_APP_PATHS.Dashboard, | ||
children: [ | ||
...ASYNC_ADMIN_ROUTES.map(toAsyncPageRoute), | ||
...LEGACY_ADMIN_ROUTES.map(toViewManagerPageRoute) | ||
] | ||
}, | ||
|
||
/* NOTE: The metadata editor might deserve a dedicated app in the future */ | ||
toViewManagerPageRoute({ | ||
path: DASHBOARD_APP_PATHS.MetadataManager, | ||
pageProps: { | ||
controller: 'edititemmetadata', | ||
view: 'edititemmetadata.html' | ||
} | ||
}), | ||
|
||
{ | ||
path: DASHBOARD_APP_PATHS.PluginConfig, | ||
element: <ServerContentPage view='/web/configurationpage' /> | ||
} | ||
] | ||
} | ||
] | ||
} | ||
]; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
import { RouteObject, redirect } from 'react-router-dom'; | ||
|
||
import { REDIRECTS } from 'apps/dashboard/routes/_redirects'; | ||
import { DASHBOARD_APP_PATHS } from 'apps/dashboard/routes/routes'; | ||
import ConnectionRequired from 'components/ConnectionRequired'; | ||
import { toAsyncPageRoute } from 'components/router/AsyncRoute'; | ||
import { toViewManagerPageRoute } from 'components/router/LegacyRoute'; | ||
import { toRedirectRoute } from 'components/router/Redirect'; | ||
import AppLayout from '../AppLayout'; | ||
import { ASYNC_USER_ROUTES } from './asyncRoutes'; | ||
import { LEGACY_PUBLIC_ROUTES, LEGACY_USER_ROUTES } from './legacyRoutes'; | ||
|
||
export const EXPERIMENTAL_APP_ROUTES: RouteObject[] = [ | ||
{ | ||
path: '/*', | ||
element: <AppLayout />, | ||
children: [ | ||
{ | ||
/* User routes: Any child route of this layout is authenticated */ | ||
element: <ConnectionRequired isUserRequired />, | ||
children: [ | ||
...ASYNC_USER_ROUTES.map(toAsyncPageRoute), | ||
...LEGACY_USER_ROUTES.map(toViewManagerPageRoute) | ||
] | ||
}, | ||
|
||
/* Public routes */ | ||
{ index: true, loader: () => redirect('/home.html') }, | ||
...LEGACY_PUBLIC_ROUTES.map(toViewManagerPageRoute) | ||
] | ||
}, | ||
|
||
/* Redirects for old paths */ | ||
...REDIRECTS.map(toRedirectRoute), | ||
|
||
/* Ignore dashboard routes */ | ||
...Object.entries(DASHBOARD_APP_PATHS).map(([, path]) => ({ | ||
path: `/${path}/*`, | ||
element: null | ||
})) | ||
]; |
Oops, something went wrong.