Skip to content

Commit

Permalink
Support hash redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Jul 21, 2021
1 parent 9d1f98f commit 07a9c9e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
21 changes: 20 additions & 1 deletion x-pack/plugins/fleet/public/applications/fleet/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,26 @@ export const AppRoutes = memo(
<CreatePackagePolicyPage />
</Route>

<Redirect to={FLEET_ROUTING_PATHS.agents} />
<Route
render={({ location }) => {
// BWC < 7.15 Fleet was using a hash router: redirect old routes using hash
const shouldRedirectHash = location.pathname === '' && location.hash.length > 0;
if (!shouldRedirectHash) {
return <Redirect to={FLEET_ROUTING_PATHS.agents} />;
}
const pathname = location.hash.replace(/^#\/fleet/, '');

return (
<Redirect
to={{
...location,
pathname,
hash: undefined,
}}
/>
);
}}
/>
</Switch>
</>
);
Expand Down
21 changes: 20 additions & 1 deletion x-pack/plugins/fleet/public/applications/integrations/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,26 @@ export const AppRoutes = memo(() => {
<Route path={INTEGRATIONS_ROUTING_PATHS.integrations}>
<EPMApp />
</Route>
<Redirect to={INTEGRATIONS_ROUTING_PATHS.integrations_all} />
<Route
render={({ location }) => {
// BWC < 7.15 Fleet was using a hash router: redirect old routes using hash
const shouldRedirectHash = location.pathname === '' && location.hash.length > 0;
if (!shouldRedirectHash) {
return <Redirect to={INTEGRATIONS_ROUTING_PATHS.integrations_all} />;
}
const pathname = location.hash.replace(/^#/, '');

return (
<Redirect
to={{
...location,
pathname,
hash: undefined,
}}
/>
);
}}
/>
</Switch>
</>
);
Expand Down

0 comments on commit 07a9c9e

Please sign in to comment.