diff --git a/src/app/page.tsx b/src/app/page.tsx index e581c39..8e81a1e 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,5 +1,11 @@ +import { cookies } from "next/headers" import { redirect } from "next/navigation" -export default function Home() { +export default async function Home() { + const latestPage = (await cookies()).get('latest_page') + if (latestPage) { + return redirect(latestPage.value) + } + return redirect("/alerts") } diff --git a/src/app/template.tsx b/src/app/template.tsx new file mode 100644 index 0000000..7066914 --- /dev/null +++ b/src/app/template.tsx @@ -0,0 +1,17 @@ +'use client' + +import { useEffect } from "react" +import { usePathname, useSearchParams } from 'next/navigation' + +export default function Template({ children }: { children: React.ReactNode }) { + const pathname = usePathname() + const searchParams = useSearchParams() + + // Save the latest seen page to a cookie + useEffect(() => { + const path = `${pathname}${searchParams.toString() !== '' ? '?' + searchParams : ''}` + document.cookie = `latest_page=${path}; path=/;` + }, [pathname, searchParams]) + + return children +}