Skip to content

Commit 23bff57

Browse files
committed
fix: call notfound if has no any notes
Signed-off-by: Innei <[email protected]>
1 parent 3ab82a2 commit 23bff57

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/app/(app)/notes/page.tsx

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { cookies } from 'next/headers'
2-
import { redirect } from 'next/navigation'
2+
import { notFound, redirect } from 'next/navigation'
33
import type { NoteWrappedWithLikedPayload } from '@mx-space/api-client'
44

55
import { getAuthFromCookie } from '~/lib/attach-fetch'
@@ -9,7 +9,7 @@ import { definePrerenderPage } from '~/lib/request.server'
99

1010
export default definePrerenderPage()({
1111
async fetcher() {
12-
const { data } =
12+
const latest =
1313
await apiClient.note.proxy.latest.get<NoteWrappedWithLikedPayload>({
1414
params: {
1515
token: getAuthFromCookie()
@@ -18,9 +18,13 @@ export default definePrerenderPage()({
1818
},
1919
})
2020

21-
return data
21+
return latest?.data
2222
},
23-
Component: ({ data: { nid, hide } }) => {
23+
Component: ({ data: nullableData }) => {
24+
if (!nullableData) {
25+
notFound()
26+
}
27+
const { nid, hide } = nullableData
2428
const jwt = cookies().get(AuthKeyNames[0])?.value
2529
if (hide) {
2630
return redirect(`/notes/${nid}?token=${jwt}`)

0 commit comments

Comments
 (0)