Skip to content

Commit d568950

Browse files
Merge pull request #15650 from openshift-cherrypick-robot/cherry-pick-15541-to-release-4.20
[release-4.20] OCPBUGS-63616: Preserve path on perspective switch
2 parents 9074839 + 0e28ec1 commit d568950

File tree

1 file changed

+11
-27
lines changed

1 file changed

+11
-27
lines changed

frontend/packages/console-app/src/hooks/usePluginRoutes.tsx

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { Route } from 'react-router-dom-v5-compat';
2+
import { createPath, Route, useLocation } from 'react-router-dom-v5-compat';
33
import {
44
useActivePerspective,
55
RoutePage as DynamicRoutePageExtension,
@@ -50,18 +50,18 @@ const InactiveRoutePage: React.FCC<InactiveRoutePageProps> = ({
5050
};
5151

5252
const RoutePage: React.FCC<RoutePageProps> = ({
53-
path,
5453
extension,
5554
activePerspective,
5655
setActivePerspective,
5756
}) => {
5857
const active = isRoutePageExtensionActive(extension, activePerspective);
58+
const location = useLocation();
5959
return active ? (
6060
<LazyRoutePage extension={extension} />
6161
) : (
6262
<InactiveRoutePage
6363
extension={extension}
64-
path={path}
64+
path={createPath(location)}
6565
setActivePerspective={setActivePerspective}
6666
/>
6767
);
@@ -73,38 +73,23 @@ export const usePluginRoutes: UsePluginRoutes = () => {
7373
const [activePerspective, setActivePerspective] = useActivePerspective();
7474
const getRoutesForExtension = React.useCallback(
7575
(extension: LoadedRoutePageExtension): React.ReactElement[] => {
76-
if (Array.isArray(extension.properties.path)) {
77-
return extension.properties.path.map((path) => (
78-
<Route
79-
{...extension.properties}
80-
path={`${path}${extension.properties.exact ? '' : '/*'}`}
81-
key={path}
82-
element={
83-
<RoutePage
84-
extension={extension}
85-
path={path}
86-
activePerspective={activePerspective}
87-
setActivePerspective={setActivePerspective}
88-
/>
89-
}
90-
/>
91-
));
92-
}
93-
return [
76+
const paths = Array.isArray(extension.properties.path)
77+
? extension.properties.path
78+
: [extension.properties.path];
79+
return paths.map((path) => (
9480
<Route
9581
{...extension.properties}
96-
path={`${extension.properties.path}${extension.properties.exact ? '' : '/*'}`}
97-
key={extension.properties.path}
82+
path={`${path}${extension.properties.exact ? '' : '/*'}`}
83+
key={path}
9884
element={
9985
<RoutePage
10086
extension={extension}
101-
path={extension.properties.path}
10287
activePerspective={activePerspective}
10388
setActivePerspective={setActivePerspective}
10489
/>
10590
}
106-
/>,
107-
];
91+
/>
92+
));
10893
},
10994
[activePerspective, setActivePerspective],
11095
);
@@ -149,7 +134,6 @@ type InactiveRoutePageProps = {
149134
};
150135

151136
type RoutePageProps = {
152-
path: string;
153137
extension: LoadedRoutePageExtension;
154138
activePerspective: string;
155139
setActivePerspective: SetActivePerspective;

0 commit comments

Comments
 (0)