0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00
astro/.changeset/smooth-cobras-help.md
Luiz Ferraz fd17f4a40b
Implement priority overrides for injected routes and redirects (#9439)
* Implement priority overrides for injected routes and redirects

* Fix ordering for route specificity

* Don't mix rules on tests

* Detailed collision detection

* Add changeset

* Remove TODO

* Add comments to clarify default values

* Update terminology

* Revert unrelated changes

* WIP

* Refactor

* Fix typo and typing

* chore: default to legacy

* chore: use experimental flag instead of option

* fix: do not throw an error on collisions

* chore: fix regression

* chore: use `continue` instead of `return`

* chore: fix tests but one

* chore: Update test

* chore: Change remaining new error to warning

* chore: Test collision warnings

* docs: Update docs of new config

* docs: Improve changesets

* chore: rename experimental flag

* chore: update changeset and docs

* Sarah editing pass

* nit: Align Markdown table

* defined definitions!

Co-authored-by: Luiz Ferraz <luiz@lferraz.com>

* added logging info to docs for experimental flag

* Yan final boss review

Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com>

* chore: Update flag name in tests

* chore: Update flag name in tests

---------

Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
Co-authored-by: Yan Thomas <61414485+Yan-Thomas@users.noreply.github.com>
2024-01-17 13:28:18 +00:00

1.7 KiB

astro
minor

Adds an experimental flag globalRoutePriority to prioritize redirects and injected routes equally alongside file-based project routes, following the same route priority order rules for all routes.

// astro.config.mjs
export default defineConfig({
  experimental: {
    globalRoutePriority: true,
  },
})

Enabling this feature ensures that all routes in your project follow the same, predictable route priority order rules. In particular, this avoids an issue where redirects or injected routes (e.g. from an integration) would always take precedence over local route definitions, making it impossible to override some routes locally.

The following table shows which route builds certain page URLs when file-based routes, injected routes, and redirects are combined as shown below:

  • File-based route: /blog/post/[pid]
  • File-based route: /[page]
  • Injected route: /blog/[...slug]
  • Redirect: /blog/tags/[tag] -> /[tag]
  • Redirect: /posts -> /blog

URLs are handled by the following routes:

Page Current Behavior Global Routing Priority Behavior
/blog/tags/astro Injected route /blog/[...slug] Redirect to /tags/[tag]
/blog/post/0 Injected route /blog/[...slug] File-based route /blog/post/[pid]
/posts File-based route /[page] Redirect to /blog

In the event of route collisions, where two routes of equal route priority attempt to build the same URL, Astro will log a warning identifying the conflicting routes.