フロントエンド開発の先端を突っ走るNext.js
next.js アプリの初期化( npx create-next-app@latest <アプリ名> ) または yarn create next-app <アプリ名> または bun create next-app <アプリ名> )

next.js (app router) で 現在のURLパス、クエリパラメーターを取得する

● next.js (app router) で 現在のURLパス、クエリパラメーターを取得する

'use client'

import { usePathname } from 'next/navigation';

// http://localhost:3001/test1?foo=bar へアクセスした場合 「/test1」 になります
const pathname = usePathname() // /test1
No.2421
05/15 16:37

edit