Debian Codegraph @

www/src/content/reference/02-headers/11-HX-Location.md

raw symbols SCIP
1 ---
2 title: "HX-Location"
3 description: "Client-side AJAX navigation to a new URL"
4 ---
5
6 The `HX-Location` response header navigates to a new URL without a full page reload.
7
8 Like clicking a boosted link—htmx fetches the content and updates the page via AJAX.
9
10 ## Simple Usage
11
12 Redirect to a path:
13
14 ```http
15 HX-Location: /dashboard
16 ```
17
18 ## Advanced Usage
19
20 Specify target and other options:
21
22 ```http
23 HX-Location: {"path":"/search", "target":"#results", "push":"false"}
24 ```
25
26 ## Options
27
28 The JSON value mirrors the htmx ajax API. All fields except `path` are optional.
29
30 - `path` - URL to load the response from (required)
31 - `target` - Element to swap the response into (defaults to `document.body`)
32 - `source` - The source element of the request
33 - `event` - Event that triggered the request
34 - `handler` - Callback to handle the response HTML
35 - `swap` - How to swap the response relative to the target
36 - `values` - Values to submit with the request
37 - `headers` - Headers to submit with the request
38 - `select` - Selects content from the response to swap
39 - `push` - Prevents or overrides the URL pushed to history (`'false'` or a path string)
40 - `replace` - Path to replace in browser history instead of pushing
41
42 ## Notes
43
44 Response headers are not processed on 3xx response codes. Return a 2xx status when using this header.
45
46 ## Example
47
48 ```python
49 headers = {'HX-Location': '/profile'}
50 return Response(content, headers=headers)
51 ```