diff --git a/src/RootAppRouter.tsx b/src/RootAppRouter.tsx
index d3056fffc6..c9c6aaf053 100644
--- a/src/RootAppRouter.tsx
+++ b/src/RootAppRouter.tsx
@@ -6,9 +6,9 @@ import {
createHashRouter
} from 'react-router-dom';
+import { DASHBOARD_APP_ROUTES } from 'apps/dashboard/routes/routes';
import { EXPERIMENTAL_APP_ROUTES } from 'apps/experimental/routes/routes';
import { useLegacyRouterSync } from 'hooks/useLegacyRouterSync';
-import { DASHBOARD_APP_ROUTES } from 'apps/dashboard/routes/routes';
const router = createHashRouter([
...EXPERIMENTAL_APP_ROUTES,
diff --git a/src/apps/dashboard/routes/routes.tsx b/src/apps/dashboard/routes/routes.tsx
index 82a606a592..7bbeb3fc4e 100644
--- a/src/apps/dashboard/routes/routes.tsx
+++ b/src/apps/dashboard/routes/routes.tsx
@@ -3,8 +3,8 @@ import { RouteObject } from 'react-router-dom';
import AppLayout from '../AppLayout';
import ConnectionRequired from 'components/ConnectionRequired';
import { ASYNC_ADMIN_ROUTES } from './_asyncRoutes';
-import { toAsyncPageRouteConfig } from 'components/router/AsyncRoute';
-import { toViewManagerPageRouteConfig } from 'components/router/LegacyRoute';
+import { toAsyncPageRoute } from 'components/router/AsyncRoute';
+import { toViewManagerPageRoute } from 'components/router/LegacyRoute';
import { LEGACY_ADMIN_ROUTES } from './_legacyRoutes';
import ServerContentPage from 'components/ServerContentPage';
@@ -24,13 +24,13 @@ export const DASHBOARD_APP_ROUTES: RouteObject[] = [
{
path: DASHBOARD_APP_PATHS.Dashboard,
children: [
- ...ASYNC_ADMIN_ROUTES.map(toAsyncPageRouteConfig),
- ...LEGACY_ADMIN_ROUTES.map(toViewManagerPageRouteConfig)
+ ...ASYNC_ADMIN_ROUTES.map(toAsyncPageRoute),
+ ...LEGACY_ADMIN_ROUTES.map(toViewManagerPageRoute)
]
},
/* NOTE: The metadata editor might deserve a dedicated app in the future */
- toViewManagerPageRouteConfig({
+ toViewManagerPageRoute({
path: DASHBOARD_APP_PATHS.MetadataManager,
pageProps: {
controller: 'edititemmetadata',
diff --git a/src/apps/experimental/routes/routes.tsx b/src/apps/experimental/routes/routes.tsx
index a07ea4dc93..3156f5f0e3 100644
--- a/src/apps/experimental/routes/routes.tsx
+++ b/src/apps/experimental/routes/routes.tsx
@@ -4,9 +4,9 @@ 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 { toAsyncPageRouteConfig } from 'components/router/AsyncRoute';
-import { toViewManagerPageRouteConfig } from 'components/router/LegacyRoute';
-import { toRedirectRouteConfig } from 'components/router/Redirect';
+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';
@@ -20,19 +20,19 @@ export const EXPERIMENTAL_APP_ROUTES: RouteObject[] = [
/* User routes: Any child route of this layout is authenticated */
element: ,
children: [
- ...ASYNC_USER_ROUTES.map(toAsyncPageRouteConfig),
- ...LEGACY_USER_ROUTES.map(toViewManagerPageRouteConfig)
+ ...ASYNC_USER_ROUTES.map(toAsyncPageRoute),
+ ...LEGACY_USER_ROUTES.map(toViewManagerPageRoute)
]
},
/* Public routes */
{ index: true, loader: () => redirect('/home.html') },
- ...LEGACY_PUBLIC_ROUTES.map(toViewManagerPageRouteConfig)
+ ...LEGACY_PUBLIC_ROUTES.map(toViewManagerPageRoute)
]
},
/* Redirects for old paths */
- ...REDIRECTS.map(toRedirectRouteConfig),
+ ...REDIRECTS.map(toRedirectRoute),
/* Ignore dashboard routes */
...Object.entries(DASHBOARD_APP_PATHS).map(([, path]) => ({
diff --git a/src/apps/stable/routes/routes.tsx b/src/apps/stable/routes/routes.tsx
index f4bbdf3b61..77f936276f 100644
--- a/src/apps/stable/routes/routes.tsx
+++ b/src/apps/stable/routes/routes.tsx
@@ -3,9 +3,9 @@ import React from 'react';
import { DASHBOARD_APP_PATHS } from 'apps/dashboard/routes/routes';
import ConnectionRequired from 'components/ConnectionRequired';
-import { toAsyncPageRouteConfig } from 'components/router/AsyncRoute';
-import { toViewManagerPageRouteConfig } from 'components/router/LegacyRoute';
-import { toRedirectRouteConfig } from 'components/router/Redirect';
+import { toAsyncPageRoute } from 'components/router/AsyncRoute';
+import { toViewManagerPageRoute } from 'components/router/LegacyRoute';
+import { toRedirectRoute } from 'components/router/Redirect';
import AppLayout from '../AppLayout';
import { REDIRECTS } from './_redirects';
import { ASYNC_USER_ROUTES } from './asyncRoutes';
@@ -20,14 +20,14 @@ export const STABLE_APP_ROUTES: RouteObject[] = [
/* User routes */
element: ,
children: [
- ...ASYNC_USER_ROUTES.map(toAsyncPageRouteConfig),
- ...LEGACY_USER_ROUTES.map(toViewManagerPageRouteConfig)
+ ...ASYNC_USER_ROUTES.map(toAsyncPageRoute),
+ ...LEGACY_USER_ROUTES.map(toViewManagerPageRoute)
]
},
/* Public routes */
{ index: true, loader: () => redirect('/home.html') },
- ...LEGACY_PUBLIC_ROUTES.map(toViewManagerPageRouteConfig),
+ ...LEGACY_PUBLIC_ROUTES.map(toViewManagerPageRoute),
/* Suppress warnings for unhandled routes */
{ path: '*', element: null }
@@ -35,7 +35,7 @@ export const STABLE_APP_ROUTES: RouteObject[] = [
},
/* Redirects for old paths */
- ...REDIRECTS.map(toRedirectRouteConfig),
+ ...REDIRECTS.map(toRedirectRoute),
/* Ignore dashboard routes */
...Object.entries(DASHBOARD_APP_PATHS).map(([, path]) => ({
diff --git a/src/components/router/AsyncRoute.tsx b/src/components/router/AsyncRoute.tsx
index ad945f5ad2..19457851d3 100644
--- a/src/components/router/AsyncRoute.tsx
+++ b/src/components/router/AsyncRoute.tsx
@@ -1,6 +1,5 @@
import loadable, { LoadableComponent } from '@loadable/component';
import React from 'react';
-import { Route } from 'react-router-dom';
export enum AsyncRouteType {
Stable,
@@ -42,32 +41,7 @@ const StableAsyncPage = loadable(
{ cacheKey: (props: AsyncPageProps) => props.page }
);
-export const toAsyncPageRoute = ({ path, page, element, type = AsyncRouteType.Stable }: AsyncRoute) => {
- let Element = element;
- if (!Element) {
- switch (type) {
- case AsyncRouteType.Dashboard:
- Element = DashboardAsyncPage;
- break;
- case AsyncRouteType.Experimental:
- Element = ExperimentalAsyncPage;
- break;
- case AsyncRouteType.Stable:
- default:
- Element = StableAsyncPage;
- }
- }
-
- return (
- }
- />
- );
-};
-
-export function toAsyncPageRouteConfig({ path, page, element, type = AsyncRouteType.Stable }: AsyncRoute) {
+export function toAsyncPageRoute({ path, page, element, type = AsyncRouteType.Stable }: AsyncRoute) {
let Element = element;
if (!Element) {
switch (type) {
diff --git a/src/components/router/HistoryRouter.tsx b/src/components/router/HistoryRouter.tsx
deleted file mode 100644
index 21e1efe0fe..0000000000
--- a/src/components/router/HistoryRouter.tsx
+++ /dev/null
@@ -1,48 +0,0 @@
-import React, { useLayoutEffect } from 'react';
-import { HistoryRouterProps, Router } from 'react-router-dom';
-import { Update } from 'history';
-
-/** Strips leading "!" from paths */
-const normalizePath = (pathname: string) => pathname.replace(/^!/, '');
-
-/**
- * A slightly customized version of the HistoryRouter from react-router-dom.
- * We need to use HistoryRouter to have a shared history state between react-router and appRouter, but it does not seem
- * to be properly exported in the upstream package.
- * We also needed some customizations to handle #! routes.
- * Refs: https://github.com/remix-run/react-router/blob/v6.3.0/packages/react-router-dom/index.tsx#L222
- */
-export function HistoryRouter({ basename, children, history }: HistoryRouterProps) {
- const [state, setState] = React.useState({
- action: history.action,
- location: history.location
- });
-
- useLayoutEffect(() => {
- const onHistoryChange = (update: Update) => {
- if (update.location.pathname.startsWith('!')) {
- // When the location changes, we need to check for #! paths and replace the location with the "!" stripped
- history.replace(normalizePath(update.location.pathname), update.location.state);
- } else {
- setState(update);
- }
- };
-
- history.listen(onHistoryChange);
- }, [ history ]);
-
- return (
-
- );
-}
diff --git a/src/components/router/LegacyRoute.tsx b/src/components/router/LegacyRoute.tsx
index e0a9df7417..983c4d84cf 100644
--- a/src/components/router/LegacyRoute.tsx
+++ b/src/components/router/LegacyRoute.tsx
@@ -1,5 +1,4 @@
import React from 'react';
-import { Route } from 'react-router-dom';
import ViewManagerPage, { ViewManagerPageProps } from '../viewManager/ViewManagerPage';
@@ -9,18 +8,6 @@ export interface LegacyRoute {
}
export function toViewManagerPageRoute(route: LegacyRoute) {
- return (
-
- }
- />
- );
-}
-
-export function toViewManagerPageRouteConfig(route: LegacyRoute) {
return {
path: route.path,
element:
diff --git a/src/components/router/Redirect.tsx b/src/components/router/Redirect.tsx
index 188493242a..d68ecdea79 100644
--- a/src/components/router/Redirect.tsx
+++ b/src/components/router/Redirect.tsx
@@ -1,5 +1,5 @@
import React from 'react';
-import { Navigate, Route, RouteObject, useLocation } from 'react-router-dom';
+import { Navigate, RouteObject, useLocation } from 'react-router-dom';
export interface Redirect {
from: string
@@ -17,17 +17,7 @@ const RedirectWithSearch = ({ to }: { to: string }) => {
);
};
-export function toRedirectRoute({ from, to }: Redirect) {
- return (
- }
- />
- );
-}
-
-export function toRedirectRouteConfig({ from, to }: Redirect): RouteObject {
+export function toRedirectRoute({ from, to }: Redirect): RouteObject {
return {
path: from,
element: