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.js】revalidatePathでlayoutを再検証する方法

Posted at

revalidatePathの基本構文

revalidatePath(path: string, type?: 'page' | 'layout'): void

revalidatePath関数は2つのパラメータを受け取ります:

  • path: 再検証したいパスの文字列(1024文字未満、大文字小文字を区別)
  • type: 再検証するパスのタイプを指定する(オプション)

layoutを再検証する方法

type'layout'を指定するとレイアウトファイルにマッチするURLと、そのレイアウトを使用するすべての下位ページを再検証します。

import { revalidatePath } from 'next/cache'

export async function revalidateBlogLayout() {
  // /blog/[slug] レイアウトとそれを使用する下位ページをすべて再検証
  revalidatePath('/blog/[slug]', 'layout')
  
  // ルートグループを使用している場合
  revalidatePath('/(main)/post/[slug]', 'layout')
}
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?