Skip to content

Commit

Permalink
Clarify route precedence in routing.mdx
Browse files Browse the repository at this point in the history
  • Loading branch information
mb21 authored Jan 23, 2024
1 parent 8047fe6 commit fd47634
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/content/docs/en/core-concepts/routing.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,17 @@ It's possible for multiple defined routes to attempt to build the same URL path.
- [...slug].astro
</FileTree>

Astro needs to know which route should be used to build the page. To do so, it sorts them according to the following rules in order:
Astro needs to know which route should be used to build the page. To do so, it sorts the routes according to the following rules (if two rules apply, the one that comes first in the following list takes precedence):

- Routes with more path segments will take precedence over less specific routes. In the example above, all routes under `/posts/` take precedence over `/[...slug].astro` at the root.
- Routes with more path segments will take precedence over routes with fewer path segments. In the example above, all routes under `/posts/` take precedence over `/[...slug].astro` at the root.
- Static routes without path parameters will take precedence over dynamic routes. E.g. `/posts/create.astro` takes precedence over all the other routes in the example.
- Dynamic routes using named parameters take precedence over rest parameters. E.g. `/posts/[page].astro` takes precedence over `/posts/[...slug].astro`.
- Pre-rendered dynamic routes take precedence over server dynamic routes.
- Endpoints take precedence over pages.
- If none of the rules above decide the order, routes are sorted alphabetically based on the default locale of your Node installation.

If multiple rules apply, the one listed first in the above list takes precedence.

Given the example above, here are a few examples of how the rules will match a requested URL to the route used to build the HTML:

- `pages/posts/create.astro` - Will build only `/posts/create`
Expand Down

0 comments on commit fd47634

Please sign in to comment.