State management. Frontend
Managing state in URL.
Workflow: Updating URL state
Identify UI variables (page, filters, sorts).
Map variables to an hx-vals JSON object using the
{% hx_urlstate %}tag.Attach hx-vals to the triggering element to merge with current URL state.
Workflow: Using hx_urlstate template tag
{% load urlstate %}in your template.Replace
hx-vals='{"page": "{{ page_num }}", "order_by": "{{ ... }}", ...}'withhx-vals='{% hx_urlstate request.GET page=page_num %}'.The tag automatically forwards all existing URL query params and lets you override specific keys.
Adding a new URL param to your views automatically propagates to all hx-vals without template changes.