Background#
Applicable to projects where the response results of route.ts
are statically handled after build
, resulting in: the interface always responding with the same data.
Method#
The method I used is to add the following code in route.ts
:
export const dynamic = 'force-dynamic'
References:
- Next.js - Data Fetching and Caching
- YouTube - 5 ways to opt out of static rendering in NextJs
- Juejin - Routing Chapter | Route Handlers
Refactoring#
Perhaps, these methods should not be used to opt out of static handling, but rather to use Server Actions.
You can also refer to: https://juejin.cn/post/7361204571828731956#heading-4