Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: return to latest page by default #19

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -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")
}
17 changes: 17 additions & 0 deletions src/app/template.tsx
Original file line number Diff line number Diff line change
@@ -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
}
Loading