-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: リロード時に背景色が必ずpinkになってしまう問題の修正 & 静的レンダリングされる箇所に動的な要素を入れてしまった問題を修正
- Loading branch information
1 parent
a4f917b
commit 06d97b8
Showing
4 changed files
with
89 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
import { Outlet, useNavigate } from "@remix-run/react"; | ||
import { type ReactNode, useLayoutEffect } from "react"; | ||
import { useSession } from "~/hooks/useSession"; | ||
import { Outlet } from "@remix-run/react"; | ||
import { redirect } from "@remix-run/react"; | ||
import type { ReactNode } from "react"; | ||
import { preload } from "swr"; | ||
import { sessionFetcher, useSession } from "~/hooks/useSession"; | ||
|
||
// _auth.**.tsx のパスへのアクセスは必ずここで前処理される | ||
export default function Layout(): ReactNode { | ||
const navigate = useNavigate(); | ||
const session = useSession(); | ||
export async function clientLoader() { | ||
const session = await preload("session", sessionFetcher); | ||
if (!session) { | ||
return redirect("/"); | ||
} | ||
|
||
useLayoutEffect(() => { | ||
if (!session) { | ||
navigate("/"); | ||
} | ||
}, [session, navigate]); | ||
return null; | ||
} | ||
|
||
// _auth.**.tsx のパスへのアクセスは必ずここで前処理される | ||
export default function Layout(): ReactNode { | ||
return <Outlet />; | ||
} |