Best practices for redirecting and displaying toast messages after a server action #77389
Unanswered
Lee-Minhoon
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
If the current server operation is successful, I need to display a toast message while redirecting to a specific page.
Here are some simple code snippets:
Case 1: Track the state with
useActionState
, then call the toast function androuter.push
.Case 2: Call the redirect function on the server, passing the desired message in the
SearchParams
, and create a component that listens to theSearchParams
to display the toast.Case 3: Call the redirect function on the server, passing the desired message in a cookie, and create a component that listens to the cookie and displays the toast.
I understand there is no one-size-fits-all answer, but I would like to know which approach is generally recommended from an SEO and performance perspective.
For example, after completing a task such as writing a post, the server generates a new postId and redirects to a new URL. I wonder if replacing the server-side redirect with
router.push
might negatively impact SEO.Beta Was this translation helpful? Give feedback.
All reactions