Closed1

Next.jsでスクロール位置の保存

high-ghigh-g

https://zenn.dev/akfm/articles/next-js-scroll-restore
next.config.jsに以下を追加する

  experimental: {
    scrollRestoration: true,
  },

↓こんな感じ

const nextConfig = {
  reactStrictMode: false,
  compiler: {
    emotion: true,
  },
  webpack: (config) => {
    config.module.rules.push({
      test: /\.svg$/,
      use: [
        {
          loader: '@svgr/webpack',
        },
      ],
    })
    return config
  },
  images: {
    disableStaticImages: true, // importした画像の型定義設定を無効にする
  },
  optimizeFonts: true,
  experimental: {
    scrollRestoration: true,
  },
}

module.exports = nextConfig
このスクラップは2023/11/09にクローズされました