2022-11-21 01:33:45 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2023-05-18 13:17:41 +02:00
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
2022-11-21 01:33:45 +01:00
|
|
|
|
|
|
|
|
import { useNavBarContext } from 'components/context/NavbarContext';
|
|
|
|
|
import { useLocation } from 'react-router-dom';
|
|
|
|
|
|
|
|
|
|
export const BACK = '__BACK__';
|
|
|
|
|
|
2023-02-06 10:06:33 +01:00
|
|
|
const useBackTo = (): { url?: string; back: boolean } => {
|
2022-11-21 01:33:45 +01:00
|
|
|
const location = useLocation<{ backLink?: string }>();
|
|
|
|
|
const { defaultBackTo } = useNavBarContext();
|
|
|
|
|
|
|
|
|
|
const url = location.state?.backLink ?? defaultBackTo;
|
|
|
|
|
return {
|
|
|
|
|
url: url === BACK ? undefined : url,
|
|
|
|
|
back: url === BACK,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default useBackTo;
|