I have a form inside a LiveView, when saved it redirects back to a page that is not a LiveView.
If there is a problem saving the form the LiveView will render an error flash.
However, if the form data is saved properly and the page redirects, what is the preferred way of rendering a Flash message on the new page?
Would setting persistent session data be the best way? Or is there another simpler solution for this use case?
If you don’t want to pollute the session you can also stash the flash in localStorage using a bit of javascript.
Simplest I could think of would be to return the flash message with the url:
query_params = %{
flash_type: "info",
flash_message: "This is the body of the flash message"
}
redirect(socket, to: "#{return_to}?#{URI.encode_query(query_params)}"
Then, in the http controller, you would retrieve the params and set the flash message accordingly.
1 Like
This is super simple, thanks.