Skip to content

Commit

Permalink
[ML] Use useEffect for legacy redirect.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Jul 16, 2020
1 parent 686e6d8 commit 2c02364
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions x-pack/plugins/ml/public/application/routing/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { FC } from 'react';
import React, { useEffect, FC } from 'react';
import { useHistory, useLocation, Router, Route, RouteProps } from 'react-router-dom';
import { Location } from 'history';

Expand Down Expand Up @@ -56,11 +56,12 @@ const LegacyHashUrlRedirect: FC = ({ children }) => {
const history = useHistory();
const location = useLocation();

if (location.hash.startsWith('#/')) {
const newHash = location.hash.replace('#', '');
history.push(newHash);
return null;
}
useEffect(() => {
if (location.hash.startsWith('#/')) {
const newHash = location.hash.replace('#', '');
history.push(newHash);
}
}, [location.hash]);

return <>{children}</>;
};
Expand Down

0 comments on commit 2c02364

Please sign in to comment.