fix: 修复 Next.js 15 async params 兼容性问题并更新文档
- 修复关键词词云页面和 API 路由中的 async params 处理 - 将 params 和 searchParams 正确声明为 Promise 类型并添加 await - 在 CLAUDE.md 中添加 Next.js 15 Breaking Change 说明 - 添加 ESLint/Prettier 配置文档 - 添加 Next.js 15 页面创建指南 - 补充故障排查部分的相关错误处理说明 Co-Authored-By: Claude (glm-4.7) <noreply@anthropic.com>
This commit is contained in:
@@ -2,12 +2,8 @@ import { KeywordCloud } from './components/KeywordCloud';
|
||||
import { getTranslations } from 'next-intl/server';
|
||||
|
||||
interface PageProps {
|
||||
params: {
|
||||
locale: string;
|
||||
};
|
||||
searchParams: {
|
||||
quarter?: string;
|
||||
};
|
||||
params: Promise<{ locale: string }>;
|
||||
searchParams: Promise<{ quarter?: string }>;
|
||||
}
|
||||
|
||||
export async function generateMetadata({
|
||||
@@ -26,10 +22,11 @@ export async function generateMetadata({
|
||||
|
||||
export default async function KeywordCloudPage({ searchParams, params }: PageProps) {
|
||||
const { locale } = await params;
|
||||
const resolvedSearchParams = await searchParams;
|
||||
const t = await getTranslations('keywordCloud');
|
||||
|
||||
// 如果 URL 中有 quarter 参数,使用它;否则使用默认季度
|
||||
const quarter = searchParams.quarter || '2024-Q1';
|
||||
const quarter = resolvedSearchParams.quarter || '2024-Q1';
|
||||
|
||||
const texts = {
|
||||
loading: t('loading'),
|
||||
|
||||
@@ -9,10 +9,10 @@ export const dynamic = 'force-dynamic';
|
||||
*/
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { quarter: string } }
|
||||
{ params }: { params: Promise<{ quarter: string }> }
|
||||
) {
|
||||
try {
|
||||
const { quarter } = params;
|
||||
const { quarter } = await params;
|
||||
|
||||
// 验证 quarter 格式
|
||||
if (!/^\d{4}-Q[1-4]$/.test(quarter)) {
|
||||
|
||||
Reference in New Issue
Block a user