#router.push dosnt wanna redirect

1 messages · Page 1 of 1 (latest)

south lotusBOT
#

Hi @digital linden. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the information provided in the knowledge sources, it seems like you're experiencing an issue where router.push() is not redirecting as expected. This could be due to action queuing, where the action might return a revalidate payload so the client needs to wait. This behavior is expected in Next.js.

As a solution, it is recommended to use redirect instead of router.push. This will also save another round trip to the server. Here's an example of how to use redirect:

import { redirect } from 'next/navigation'
 
export async function GET(request: Request) {
  redirect('<https://nextjs.org/'>)
}

This code is an example of how to use the redirect function in a server action. In your case, you would replace '<https://nextjs.org/'> with the URL you want to redirect to, which in your case would be /posts/${params.id}.

You can find more information about the redirect function in the Next.js documentation (https://nextjs.org/docs/app/api-reference/functions/redirect).

Please note that this is a suggestion based on the information provided in the knowledge sources and may not solve your issue completely. If the problem persists, it would be helpful to provide more context or consider opening an issue in the Next.js GitHub repository.

#

Sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: