Replies: 1 comment 1 reply
-
Hey, if you want to do a full page redirect, I think you indeed won't really have the choice; you'd have to find a way to carry some value around to indicate that a toast should be rendered on your new page. You could do that for example either by adding some parameter values to your redirection URL (such as Oob swap doesn't make much sense if you're making a full redirect, as it should be your new page's responsibility to display the expected content in the first place, on the initial load What you can do on the other hand and you have already found it ; using So to answer your last question, don't worry, that isn't hackish, it's what this feature was made for, and using that push-url method is how you make a Single Page Application after all! |
Beta Was this translation helpful? Give feedback.
-
Dear HTMX community,
Thank you for this great tool. I was recently trying to implement toast-style notifications. The way I did so was by having a main toast-container protected by
hx-preserve
, and piggy-backing the toasts as oob-swaps.With the following base template:
Then when sending say a PUT request to /items/:id I would return
But there's also the common case of receiving a redirect from the server (
HX-Location
), which particularly makes sense when adding a resource (and so redirecting to that resource URL, like/items/:new_id
) or deleting it (in that case redirecting to the general list at/items
)What would be nice, in those cases, is to be able to piggy-back the usual oob Toast and also redirect the user to the relevant URL. This is what I came up with:
This accomplishes what I wish, but feels a little bit hackish, and I wonder if there are side-effects I haven't yet encountered. Any thoughts on this particular use case?
It would be nice to have something like
HX-Swap-Location: /items
which would basically accomplish the same thing under the hood.Thank you.
Beta Was this translation helpful? Give feedback.
All reactions