htmxRedirect function

Response htmxRedirect(
  1. Request request,
  2. String location, {
  3. int status = 302,
})

A redirect to location that htmx follows as a page navigation.

The browser follows a 302 inside htmx's request, and htmx then swaps the page it lands on into the target element. For an htmx request this answers 200 with HX-Redirect: location instead, which makes htmx load location as a full page; any other request gets an ordinary redirect with status (use 303 after a PUT, PATCH or DELETE).

Implementation

Response htmxRedirect(Request request, String location, {int status = 302}) =>
    request.isHtmx
    ? Response(headers: Headers(<String, Object>{'hx-redirect': location}))
    : Response.redirect(location, status: status);