Skip to content

Instantly share code, notes, and snippets.

@sommeeeer
Last active May 29, 2025 09:06
Show Gist options
  • Select an option

  • Save sommeeeer/5bd65f8cb32c2fff361452bf0e75444a to your computer and use it in GitHub Desktop.

Select an option

Save sommeeeer/5bd65f8cb32c2fff361452bf0e75444a to your computer and use it in GitHub Desktop.
// RedirectAction.tsx
import { redirect } from 'next/navigation';
export default function RedirectAction() {
return (
<form
action={async () => {
'use server';
redirect(`/posts/2`);
}}
>
<button type="submit">Server Action Redirect to /posts/2</button>
</form>
);
}
// app/posts/[id]/page.tsx
export default async function Page({
params,
}: {
params: Promise<{ id: string }>;
}) {
const { id } = await params;
return <div>My Post: {id}</div>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment