0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Next.js14 App Router 動的ルートがNot Foundで詰まった話

Posted at

はじめに

Next.js14のApp Routerで動的ルートを構築していた際に詰まった箇所があったので、
備忘として残す。

発生事象

動的ルートのフォルダ構成とリンククリック時の遷移先URLが一致しているにもかかわらず、
404 NotFoundしか表示されない。

フォルダ構成

スクリーンショット 2024-07-23 145248.png

遷移先URL

スクリーンショット 2024-07-23 145607.png

試したこと

・キャッシュクリア
・動的ルートを/app/bbs-posts/[id]/page.tsxで設定しており、idの型をnumberからstringに変換
・page.tsxの拡張子を.jsxに変更

結果

上記3つ目の拡張子を変更した際にモジュールインポートの再読み込みが行われ?解決した。
※解決後、拡張子は元の.tsxに戻してます。

まとめ

また同事象が発生した場合は、以下手順で確認する。

1.リンククリック時の遷移先URLが意図したパスになっているか?
2.1のURLにのっとったフォルダ構成となっているか?
3.表示したいページ(2のフォルダ内にあるpage.tsx)を再作成する。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?