0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00
astro/.changeset/twenty-cobras-push.md
Kevin 4e5cc5aadd
Add base to paginate (#11253)
* add base to `paginate()`

* update tests

* remove condicional cache

* add missing base param

* add missing leading slash in tests

* remove default

* fix: add missing trailing slash in pagination root test

* Add feedback from code review

* add changeset

* rebase and run format code

* Update .changeset/twenty-cobras-push.md

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

* add code diff

* fix rebase

* Apply suggestions from code review

Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>

* chore: merge next

* update changeset

---------

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
2024-08-28 10:31:32 +01:00

1,004 B

astro
major

Changes the data returned for page.url.current, page.url.next, page.url.prev, page.url.first and page.url.last to include the value set for base in your Astro config.

Previously, you had to manually prepend your configured value for base to the URL path. Now, Astro automatically includes your base value in next and prev URLs.

If you are using the paginate() function for "previous" and "next" URLs, remove any existing base value as it is now added for you:

---
export async function getStaticPaths({ paginate }) {
  const astronautPages = [{
    astronaut: 'Neil Armstrong',
  }, {
    astronaut: 'Buzz Aldrin',
  }, {
    astronaut: 'Sally Ride',
  }, {
    astronaut: 'John Glenn',
  }];
  return paginate(astronautPages, { pageSize: 1 });
}
const { page } = Astro.props;
// `base: /'docs'` configured in `astro.config.mjs` 
- const prev = "/docs" + page.url.prev;
+ const prev = page.url.prev;
---
<a id="prev" href={prev}>Back</a>