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

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

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

import { usePathname } from 'next/navigation';

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

edit