diff --git a/apps/readest-app/src/app/library/page.tsx b/apps/readest-app/src/app/library/page.tsx index 8a5495ff..92f8efc8 100644 --- a/apps/readest-app/src/app/library/page.tsx +++ b/apps/readest-app/src/app/library/page.tsx @@ -143,6 +143,10 @@ const LibraryPageContent = ({ searchParams }: { searchParams: ReadonlyURLSearchP }, }); + useEffect(() => { + sessionStorage.setItem('lastLibraryParams', searchParams?.toString() || ''); + }, [searchParams]); + useEffect(() => { const doCheckAppUpdates = async () => { if (appService?.hasUpdater && settings.autoCheckUpdates) { diff --git a/apps/readest-app/src/components/Providers.tsx b/apps/readest-app/src/components/Providers.tsx index e4ef2ce2..01bebb41 100644 --- a/apps/readest-app/src/components/Providers.tsx +++ b/apps/readest-app/src/components/Providers.tsx @@ -2,9 +2,8 @@ import '@/utils/polyfill'; import i18n from '@/i18n/i18n'; -import { useEffect, useRef } from 'react'; +import { useEffect } from 'react'; import { IconContext } from 'react-icons'; -import { usePathname } from 'next/navigation'; import { AuthProvider } from '@/context/AuthContext'; import { useEnv } from '@/context/EnvContext'; import { CSPostHogProvider } from '@/context/PHContext'; @@ -28,16 +27,6 @@ const Providers = ({ children }: { children: React.ReactNode }) => { const iconSize = useDefaultIconSize(); useSafeAreaInsets(); // Initialize safe area insets - const pathname = usePathname(); - const prevPathnameRef = useRef(null); - - useEffect(() => { - if (prevPathnameRef.current !== null) { - sessionStorage.setItem('lastPath', prevPathnameRef.current); - } - prevPathnameRef.current = pathname; - }, [pathname]); - useEffect(() => { const handlerLanguageChanged = (lng: string) => { document.documentElement.lang = lng; diff --git a/apps/readest-app/src/utils/nav.ts b/apps/readest-app/src/utils/nav.ts index 384be0e2..59af63eb 100644 --- a/apps/readest-app/src/utils/nav.ts +++ b/apps/readest-app/src/utils/nav.ts @@ -82,10 +82,10 @@ export const navigateToLibrary = ( navOptions?: { scroll?: boolean }, navBack?: boolean, ) => { - const lastPath = typeof window !== 'undefined' ? sessionStorage.getItem('lastPath') : null; - if (navBack && lastPath === '/library') { - router.back(); - return; + const lastLibraryParams = + typeof window !== 'undefined' ? sessionStorage.getItem('lastLibraryParams') : null; + if (navBack && lastLibraryParams) { + queryParams = lastLibraryParams; } router.replace(`/library${queryParams ? `?${queryParams}` : ''}`, navOptions);