Skip to content

Commit 440fed4

Browse files
committed
docs: clarify route pathname normalization
1 parent 4a89ecd commit 440fed4

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

src/content/docs/en/guides/upgrade-to/v6.mdx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -832,13 +832,16 @@ If you have route files with `%25` in the filename, rename them to use a differe
832832
src/pages/test%25file.astro
833833
src/pages/test-file.astro
834834
```
835-
Astro v6 also changed how URLs and route parameters are handled at runtime.
835+
## Changed: Route pathname normalization
836836
837-
`Astro.url` returns a normalized and partially decoded URL, so it may differ from `new URL(Astro.request.url)`.
837+
Since Astro v6, route pathnames are partially decoded during route normalization. This means `Astro.url.pathname` may differ from `new URL(Astro.request.url).pathname` for percent-encoded route segments.
838838
839-
`Astro.params` values are automatically decoded, and percent-encoded characters in pathnames or parameters (like `%25`) may appear decoded in `Astro.url` or `Astro.params`.
839+
This also affects route params derived from normalized pathnames.
840+
841+
### What should I do?
842+
843+
If you need access to the original encoded pathname, use `new URL(Astro.request.url).pathname` instead of `Astro.url.pathname`.
840844
841-
If you need the raw request URL with no decoding, use `Astro.request.url` and parse it manually.
842845
843846
### Removed: `astro:ssr-manifest` virtual module (Integration API)
844847

src/content/docs/en/reference/api-reference.mdx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ In static builds, this will be the `params` returned by `getStaticPaths()` used
137137

138138
When routes are rendered on demand, `params` can be any value matching the path segments in the dynamic route pattern.
139139

140-
`params` values are automatically decoded from route pathnames.
141-
142140
```astro title="src/pages/posts/[id].astro" "Astro.params"
143141
---
144142
import { getPost } from '../api';
@@ -165,11 +163,9 @@ See also: [`params`](/en/reference/routing-reference/#params)
165163
<Since v="1.0.0" />
166164
</p>
167165

168-
`url` is a [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) object constructed from the current `request.url` value. It is useful for interacting with individual properties of the request URL, like pathname and origin.
169-
170-
`Astro.url` is a normalized `URL` instance derived from `Astro.request.url`.
166+
A normalized [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) object derived from the current `request.url` value. It is useful for interacting with individual properties of the request URL, like pathname and origin.
171167

172-
In Astro v6, the pathname is partially decoded during route normalization, so `Astro.url.pathname` may differ from `new URL(Astro.request.url).pathname` for percent-encoded route segments.
168+
Since Astro v6, the pathname is partially decoded during route normalization. This means `Astro.url.pathname` may differ from `new URL(Astro.request.url).pathname` for percent-encoded route segments.
173169

174170
`url` will be a `localhost` URL in dev mode. When building a site, prerendered routes will receive a URL based on the [`site`](/en/reference/configuration-reference/#site) and [`base`](/en/reference/configuration-reference/#base) options. If `site` is not configured, prerendered pages will receive a `localhost` URL during builds as well.
175171

src/content/docs/en/reference/configuration-reference.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,8 @@ In some specific contexts (e.g., applications behind trusted reverse proxies wit
517517

518518
When not configured, `X-Forwarded-Host` headers are not trusted and will be ignored.
519519

520+
When deploying behind reverse proxies or serverless platforms (for example Vercel), configure `allowedDomains` so Astro can safely trust forwarded host headers during origin validation.
521+
520522
#### security.actionBodySizeLimit
521523

522524
<p>

0 commit comments

Comments
 (0)