diff options
author | 2024-12-19 04:23:46 -0800 | |
---|---|---|
committer | 2024-12-19 12:23:46 +0000 | |
commit | 3f557b2e3268d385454e505c1eebe52b180118a4 (patch) | |
tree | 131c7b16f71954841c0684ec516977e6c91da959 /.changeset/wise-boxes-develop.md | |
parent | e56af4a3d7039673658e4a014158969ea5076e32 (diff) | |
download | astro-3f557b2e3268d385454e505c1eebe52b180118a4.tar.gz astro-3f557b2e3268d385454e505c1eebe52b180118a4.tar.zst astro-3f557b2e3268d385454e505c1eebe52b180118a4.zip |
[ci] release (#12762)astro@5.1.0
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Diffstat (limited to '.changeset/wise-boxes-develop.md')
-rw-r--r-- | .changeset/wise-boxes-develop.md | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/.changeset/wise-boxes-develop.md b/.changeset/wise-boxes-develop.md deleted file mode 100644 index 5b7d0825e..000000000 --- a/.changeset/wise-boxes-develop.md +++ /dev/null @@ -1,44 +0,0 @@ ---- -'astro': minor ---- - -Adds a new `getActionPath()` helper available from `astro:actions` - -Astro 5.1 introduces a new helper function, `getActionPath()` to give you more flexibility when calling your action. - -Calling `getActionPath()` with your action returns its URL path so you can make a `fetch()` request with custom headers, or use your action with an API such as `navigator.sendBeacon()`. Then, you can [handle the custom-formatted returned data](https://docs.astro.build/en/guides/actions/#handling-returned-data) as needed, just as if you had called an action directly. - -This example shows how to call a defined `like` action passing the `Authorization` header and the [`keepalive`](https://developer.mozilla.org/en-US/docs/Web/API/Request/keepalive) option: - -```astro -<script> -// src/components/my-component.astro -import { actions, getActionPath } from 'astro:actions' - -await fetch(getActionPath(actions.like), { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - Authorization: 'Bearer YOUR_TOKEN' - }, - body: JSON.stringify({ id: 'YOUR_ID' }), - keepalive: true -}) -</script> -``` - -This example shows how to call the same `like` action using the [`sendBeacon`](https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon) API: - -```astro -<script> -// src/components/my-component.astro -import { actions, getActionPath } from 'astro:actions' - -navigator.sendBeacon( - getActionPath(actions.like), - new Blob([JSON.stringify({ id: 'YOUR_ID' })], { - type: 'application/json' - }) -) -</script> -``` |