LoginSignup
0
0

More than 1 year has passed since last update.

【Next.js】詳細ページに遷移した後にリロードすると404になった時の対処方法

Posted at

概要

next/linknext/routerを利用した詳細ページへの遷移時に遷移は成功するが、ページを更新したり別タブで開こうとすると404が発生する事象に遭遇した。
解決まで少し沼ったので解決方法をまとめておく

環境

  • Next.js v12.1.6

対処方法

trailingSlashを有効にすることで以下の問題が解決したことで404になる事象が解決したようです。

As Is

/pages/hoge/index.tsxhoge.htmlで書き出される

To Be

/pages/hoge/index.tsx/hoge/index.htmlで書き出される

next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
    // https://github.com/vercel/next.js/discussions/10522#discussioncomment-28307
    trailingSlash: true, // 追加!
    typescript: {}
};

module.exports = nextConfig;
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