Skip to content

Commit 0170dfa

Browse files
committed
feat(links): change document title for according post title
1 parent 0e3ba8d commit 0170dfa

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

app/routes/blog.$slug.tsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { defer, LoaderFunction, LoaderFunctionArgs } from "@remix-run/node";
2-
import { Await, useLoaderData } from "@remix-run/react";
2+
import { Await, useLoaderData, useParams } from "@remix-run/react";
33
import { NotionAPI } from "notion-client";
44
import React, { lazy, Suspense } from "react";
55
import { ClientOnly } from "remix-utils/client-only";
@@ -103,6 +103,8 @@ export const loader: LoaderFunction = async ({
103103

104104
export default function NotionRoute() {
105105
const { recordMap } = useLoaderData<typeof loader>();
106+
const { slug } = useParams();
107+
const post = posts.find((p) => p.slug === slug);
106108

107109
return (
108110
<div className="flex min-h-screen flex-col">
@@ -117,9 +119,12 @@ export default function NotionRoute() {
117119
}
118120
>
119121
<Await resolve={recordMap}>
120-
{(resolvedRecordMap: ExtendedRecordMap) => (
121-
<NotionPage recordMap={resolvedRecordMap} />
122-
)}
122+
{(resolvedRecordMap: ExtendedRecordMap) => {
123+
if (post) {
124+
document.title = post.title;
125+
}
126+
return <NotionPage recordMap={resolvedRecordMap} />;
127+
}}
123128
</Await>
124129
</Suspense>
125130
</div>

0 commit comments

Comments
 (0)