Overview

hlivekit.Redirect sets window.location.href in the browser from an attribute the server adds. Add it to any element from inside an event handler and, as soon as the diff carrying it applies, the browser navigates — a full page load, not a WebSocket-only view swap, so it works just as well for leaving the app entirely as it does for moving between its own pages.

API

  • hlivekit.Redirect(url string) l.Attributer — navigate the browser to url.

Use case

After a login form succeeds, send the user on to their dashboard. After deleting a resource, send them back to its list page rather than leaving them looking at a now-empty detail view.

Code sample

form.Add(l.PreventDefault(), l.On("submit", func(ctx context.Context, e l.Event) { user, err := login(email.Get(), password.Get()) if err != nil { errMessage.Set(err.Error()) return } form.Add(hlivekit.Redirect("/dashboard")) }))