Next.js Discord

Discord Forum

redirect not working properly

Unanswered
BannedNull posted this in #help-forum
Open in Discord
I have a component in the layout on my dashboard and when I run the server function it doesn't do the redirection, is that a bug?

/app/(root)/dashboard/layout.tsx
import {removeItem} from "@/lib/actions"

export default function Layout({ children }: { children: React.ReactNode }) {
  const handleRemove = async (id: number) => {
    await removeItem(id);
  };

  return (
    <>
      <ul>
        <li onClick={() => handleRemove(1)}>Item 01</li>
        <li onClick={() => handleRemove(2)}>Item 02</li>
      </ul>
      {children}
    </>
  );
}

/lib/actions.ts
'use server';

import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";

export function removeItem(id: number) {
  //prisma delete id
  revalidatePath('/dashboard'); //no work
  redirect('/dashboard'); // no work
}


from page.tsx it works

2 Replies

from page.tsx it works
I think that's expected behavior, maybe you can try next/after