feat: 在删除和创建代码片段功能中添加路径重新验证,避免使用缓存界面

This commit is contained in:
ngc2207 2024-11-12 18:06:44 +08:00
parent 8e869954f3
commit 136425a0ea

View File

@ -1,6 +1,7 @@
"use server"; "use server";
import { db } from "@/db"; import { db } from "@/db";
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
export async function editSnippet(id: number, code: string) { export async function editSnippet(id: number, code: string) {
@ -15,6 +16,7 @@ export async function editSnippet(id: number, code: string) {
export async function deleteSnippet(id: number) { export async function deleteSnippet(id: number) {
await db.snippet.delete({ where: { id } }); await db.snippet.delete({ where: { id } });
revalidatePath("/");
redirect("/"); redirect("/");
} }
@ -54,6 +56,7 @@ export async function createSnippet(
}; };
} }
} }
revalidatePath("/");
// Redirect the user back to the root route // Redirect the user back to the root route
redirect("/"); redirect("/");
} }