mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-24 17:51:14 +02:00
feat: futureproofing last viewed page redirect (#9794)
You should not be able to break initial page redirect even if you set '/' as target. It is not strictly needed in the current code path. This will create a redirect loop only if you manually modify local storage. It just makes this part safer if it is ever modified.
This commit is contained in:
parent
ee9b0a0193
commit
6403ae7f9b
@ -6,10 +6,12 @@ import Loader from './common/Loader/Loader';
|
|||||||
import { useLocalStorageState } from 'hooks/useLocalStorageState';
|
import { useLocalStorageState } from 'hooks/useLocalStorageState';
|
||||||
import { useAuthUser } from 'hooks/api/getters/useAuth/useAuthUser';
|
import { useAuthUser } from 'hooks/api/getters/useAuth/useAuthUser';
|
||||||
|
|
||||||
|
const defaultPage = '/personal';
|
||||||
|
|
||||||
export const useLastViewedPage = (location?: Location) => {
|
export const useLastViewedPage = (location?: Location) => {
|
||||||
const [state, setState] = useLocalStorageState<string>(
|
const [state, setState] = useLocalStorageState<string>(
|
||||||
'lastViewedPage',
|
'lastViewedPage',
|
||||||
'/personal',
|
defaultPage,
|
||||||
7 * 24 * 60 * 60 * 1000, // 7 days, left to promote seeing Personal dashboard from time to time
|
7 * 24 * 60 * 60 * 1000, // 7 days, left to promote seeing Personal dashboard from time to time
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -55,5 +57,9 @@ export const InitialRedirect = () => {
|
|||||||
return <Navigate to={`/projects/${lastViewedProject}`} replace />;
|
return <Navigate to={`/projects/${lastViewedProject}`} replace />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <Navigate to={lastViewedPage} replace />;
|
if (lastViewedPage && lastViewedPage !== '/') {
|
||||||
|
return <Navigate to={lastViewedPage} replace />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <Navigate to={defaultPage} replace />;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user