Server actions redirect and revalidate
Unanswered
Schneider’s Smooth-fronted Caima… posted this in #help-forum
Original message was deleted.
18 Replies
Why do you need to go to the details page just to delete something?
Just delete it from list page itself?
Say your list page shows a table. So your table could have a Lil action menu on the far right side that can use a delete button. Just put the delete code there and do a revalidate path after that.
Asiatic Lion
@<Milind ツ /> what if I'm adding a new article and after publishing it, I want to redirect to the article page?
now I'm doing router.push as well...
now I'm doing router.push as well...
Yeah, this is behavior is weird. For some reason they decided that if a user uses redirect, they don't need to return data from the server action. Which is not true, if you want you give your user some details, or set some client side state.
In these cases, where I do really need to access the returned data, I either:
- use router.push()
- call a separate server action just to redirect user (i.e. to close an intercepted route)
Both approaches are suboptimal, cause they cause another network roundtrip, but here we are
In these cases, where I do really need to access the returned data, I either:
- use router.push()
- call a separate server action just to redirect user (i.e. to close an intercepted route)
Both approaches are suboptimal, cause they cause another network roundtrip, but here we are
@Asiatic Lion <@397055198545051650> what if I'm adding a new article and after publishing it, I want to redirect to the article page?
now I'm doing router.push as well...
You were talking about going to details page and deleting the item so pointed out
Ofc if you are going to a page that adds a new article then sure you need some client features.
Then you can make use of router.back() along with revalidatePath()
it automatically handles page content that way (atleast for me)
Next.js team, yeah
I was thinking about it, and I think they should make it optional. If redirect is being called from a server action, there should be a way to pass a behavior parameter, i.e.
redirect({ behavior: 'doNotThrow' })I use the similar approach. This is the only way to pass error messages from the server to the client. However, if you have only one generic error, i.e. you show the same error message if something happened during deleting the tour, you could omit that and use try/catch in your client component handler
Note: you still have to use try/catch in the client component handler to catch network errors
Tried using router.replace()?
Not if u provide url
permanentRedirect(/tours, replace). So it won't go back to any previous url