withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.63k stars 2.47k forks source link

The "page" prop in paginated dynamic routes doesn’t handle base URLs #10358

Closed amxmln closed 4 weeks ago

amxmln commented 8 months ago

Astro Info

Astro                    v4.4.13
Node                     v20.11.0
System                   macOS (arm64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             astro-imagetools
                         @astrojs/vue

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When having a base option configured, the page prop resulting from having a dynamic route with paginated content doesn’t take that base into account.

This means that the URLs in page.url.prev and page.url.next are not prefixed with the configured base. This (strangely) doesn't cause issues in development mode, but when running a preview after build, the links don’t work correctly.

What's the expected result?

I believe page.url.prev and page.url.next should be correctly prefixed with base if it is defined in the configuration. If there are issues with that, the behaviour should at least be documented so developers can manually handle the case.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-kzsh3y?file=src%2Fpages%2Findex.astro

Participation

bluwy commented 8 months ago

I think it makes sense to add the base by default, but if we change it now, I feel like it would break many existing setups. Documenting it might be a good solution for now, and we can revisit this in Astro 5.

matthewp commented 8 months ago

I don't quite understand, what API is this in reference to? What is page.url.next? Can you link to docs on this API?

bluwy commented 8 months ago

It's https://docs.astro.build/en/reference/api-reference/#pageurlprev. Currently paginate() generates it, but it doesn't have knowledge of the current base IIUC.

ematipico commented 4 weeks ago

This has been implemented in v5