Last active
September 16, 2025 00:53
-
-
Save kobitoDevelopment/ec6638444ae1491ae71b364ce562d9b0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 'use client' | |
| import { usePathname } from 'next/navigation' | |
| export default function FugaPage() { | |
| const pathname = usePathname() | |
| const isHoge = pathname.includes('/hoge') | |
| return ( | |
| <div> | |
| <h1>Fuga Page (Client Side)</h1> | |
| <p>現在のパス: {pathname}</p> | |
| <p>判定結果: {isHoge ? 'hogeです' : 'hogeではありません'}</p> | |
| </div> | |
| ) | |
| } |
This file contains hidden or 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
| 'use client' | |
| import { usePathname } from 'next/navigation' | |
| export default function HogePage() { | |
| const pathname = usePathname() | |
| const isHoge = pathname.includes('/hoge') | |
| return ( | |
| <div> | |
| <h1>Hoge Page (Client Side)</h1> | |
| <p>現在のパス: {pathname}</p> | |
| <p>判定結果: {isHoge ? 'hogeです' : 'hogeではありません'}</p> | |
| </div> | |
| ) | |
| } |
This file contains hidden or 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
| import { NextResponse } from "next/server"; | |
| import type { NextRequest } from "next/server"; | |
| export function middleware(request: NextRequest) { | |
| /* | |
| src/をエイリアスにしている場合、middleware.tsを配置する場所はプロジェクトルートではなくsrc/直下にする必要がある | |
| */ | |
| const requestHeaders = new Headers(request.headers); | |
| requestHeaders.set("x-pathname", request.nextUrl.pathname); | |
| return NextResponse.next({ | |
| request: { | |
| headers: requestHeaders, | |
| }, | |
| }); | |
| } | |
| export const config = { | |
| matcher: "/((?!api|_next/static|_next/image|favicon.ico).*)", | |
| }; |
This file contains hidden or 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
| import { headers } from "next/headers"; | |
| export default async function FugaPage() { | |
| const headersList = await headers(); | |
| const pathname = headersList.get("x-pathname") || ""; | |
| const isHoge = pathname.includes("/hoge"); | |
| return ( | |
| <div> | |
| <h1>Fuga Page</h1> | |
| <p>現在のパス: {pathname}</p> | |
| <p>判定結果: {isHoge ? "hogeです" : "hogeではありません"}</p> | |
| </div> | |
| ); | |
| } |
This file contains hidden or 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
| import { headers } from "next/headers"; | |
| export default async function HogePage() { | |
| const headersList = await headers(); | |
| const pathname = headersList.get("x-pathname") || ""; | |
| const isHoge = pathname.includes("/hoge"); | |
| return ( | |
| <div> | |
| <h1>Hoge Page (Server Side)</h1> | |
| <p>現在のパス: {pathname}</p> | |
| <p>判定結果: {isHoge ? "hogeです" : "hogeではありません"}</p> | |
| </div> | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment