f-update-url
This commit is contained in:
@@ -210,15 +210,42 @@ The `POST` button above only submits as a partial because the form has an
|
||||
|
||||
Keep the following in mind when using other methods:
|
||||
|
||||
- **The URL doesn't change:** Unlike `GET` and `POST`, these methods leave the
|
||||
URL in the address bar as it is. See
|
||||
[Controlling the URL](#controlling-the-url).
|
||||
- **Redirects:** To redirect after a `DELETE`, `PATCH` or `PUT`, respond with
|
||||
status `303 See Other`. With a `301` or `302`, `fetch()` sends the request to
|
||||
the new URL again with the same method.
|
||||
the new URL again with the same method. The partials from the redirect target
|
||||
are applied, but the URL only changes to it if you set `f-update-url="true"`.
|
||||
- **Without JavaScript:** If JavaScript isn't loaded, the browser doesn't
|
||||
recognize the method and submits the form as a `GET` request instead, with the
|
||||
fields in the URL. If a form has to work without JavaScript, use `POST`.
|
||||
- **CSRF protection:** The [CSRF middleware](/docs/plugins/csrf) treats these
|
||||
methods like `POST`, so they get the same checks.
|
||||
|
||||
### Controlling the URL
|
||||
|
||||
When a `GET` or `POST` form is submitted as a partial, Fresh replaces the URL in
|
||||
the address bar with the form's action URL, or with the URL it was redirected
|
||||
to. Other methods leave the URL as it is, so a `DELETE` to `/items/1` doesn't
|
||||
leave `/items/1` in the address bar.
|
||||
|
||||
To change this, set `f-update-url` on the form or on the submit button. The
|
||||
button's value wins if both have one.
|
||||
|
||||
- `f-update-url="true"` updates the URL, for any method
|
||||
- `f-update-url="false"` leaves the URL as it is, for any method
|
||||
|
||||
```tsx
|
||||
<form action="/search" f-update-url="false">
|
||||
<input name="q" />
|
||||
<button type="submit">Search</button>
|
||||
</form>;
|
||||
```
|
||||
|
||||
> [info]: Use the strings `"true"` and `"false"`. Preact leaves the attribute
|
||||
> out when you pass the boolean `{false}`, so Fresh falls back to the default.
|
||||
|
||||
### Sending requests from buttons
|
||||
|
||||
A `<button>` with an `f-partial` attribute also triggers a partial request on
|
||||
|
||||
Reference in New Issue
Block a user