Skip to content

docs: clarify Astro.url and Astro.params runtime behavior#13903

Open
Prayaksh wants to merge 5 commits into
withastro:mainfrom
Prayaksh:fix/astro-url-runtime-docs
Open

docs: clarify Astro.url and Astro.params runtime behavior#13903
Prayaksh wants to merge 5 commits into
withastro:mainfrom
Prayaksh:fix/astro-url-runtime-docs

Conversation

@Prayaksh

Copy link
Copy Markdown

Description (required)

This PR clarifies the runtime behavior of URL decoding in Astro v6 dynamic routes.

The original issue was reported in the withastro/astro repository, and after maintainer confirmation it was identified as a documentation gap rather than a runtime bug.

In Astro v6, Astro.url returns a normalized and partially decoded URL, which may differ from new URL(Astro.request.url). Additionally, Astro.params values are automatically decoded. This behavior was not clearly documented in the v6 upgrade guide section covering percent-encoded routes.

This update adds a runtime clarification under the “Percent-Encoding in routes” section to reflect the actual behavior and avoid confusion for users working with encoded dynamic route segments.


Related issues & labels (optional)


@netlify

netlify Bot commented May 17, 2026

Copy link
Copy Markdown

Deploy Preview for astro-docs-2 ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit aeb1b2e
🔍 Latest deploy log https://app.netlify.com/projects/astro-docs-2/deploys/6a1fad6ba99a000008fcce5e
😎 Deploy Preview https://deploy-preview-13903--astro-docs-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@astrobot-houston

Copy link
Copy Markdown
Contributor

Hello! Thank you for opening your first PR to Astro’s Docs! 🎉

Here’s what will happen next:

  1. Our GitHub bots will run to check your changes.
    If they spot any broken links you will see some error messages on this PR.
    Don’t hesitate to ask any questions if you’re not sure what these mean!

  2. In a few minutes, you’ll be able to see a preview of your changes on Netlify 🥳.

  3. One or more of our maintainers will take a look and may ask you to make changes.
    We try to be responsive, but don’t worry if this takes a few days.

@astrobot-houston

astrobot-houston commented May 17, 2026

Copy link
Copy Markdown
Contributor

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

File Note
en/guides/upgrade-to/v6.mdx Source changed, localizations will be marked as outdated.
en/reference/api-reference.mdx Source changed, localizations will be marked as outdated.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

@ArmandPhilippot ArmandPhilippot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution!

If this is indeed a documentation issue (I wouldn't say "probably" means "confirmation"), this addition can be helpful but it doesn't fully fix the issue.

The issue mentions a misleading description in https://docs.astro.build/en/reference/api-reference/#url and potentially in https://docs.astro.build/en/reference/api-reference/#params

@ematipico can you confirm we should fix the docs? Or the fix mentioned by the bot could work and no docs change is required?

Edit: I hadn't followed the linked PR, it seems this might have been fixed in withastro/astro#16808 ?

@ArmandPhilippot ArmandPhilippot added improve or update documentation Enhance / update existing documentation (e.g. add example, improve description, update for changes) should this be documented? Need to figure out whether this is something to add to documentation or not labels May 21, 2026
@Prayaksh

Copy link
Copy Markdown
Author

I realize now that I acted on the “probably” comment before the issue was fully confirmed. Thank you for clarifying. I’m still learning the process and will make sure to verify before updating the docs in the future.

@ematipico

Copy link
Copy Markdown
Member

The documentation update is still valid, because not all characters can be safely decoded e.g. %25AB. Even after my fix, there are still cases that are uncertain, so Astro play it safe and returns an error.

@ArmandPhilippot ArmandPhilippot removed the should this be documented? Need to figure out whether this is something to add to documentation or not label May 22, 2026
@ArmandPhilippot

Copy link
Copy Markdown
Member

Okay, thanks Ema!

And no problem @Prayaksh! Are you still willing to check if other pages require an update? It seems we at least need to update https://docs.astro.build/en/reference/api-reference/#url

@Prayaksh

Copy link
Copy Markdown
Author

Thanks @ArmandPhilippot ! I’ve updated the Astro.url and Astro.params API reference docs to clarify the normalization/decoding behavior as well.

@ArmandPhilippot ArmandPhilippot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update! But, I think the upgrade guide addition is misplaced and your description for Astro.params doesn't seem correct.

Comment thread src/content/docs/en/reference/api-reference.mdx Outdated
Comment thread src/content/docs/en/reference/api-reference.mdx Outdated
Comment thread src/content/docs/en/reference/api-reference.mdx Outdated
Comment thread src/content/docs/en/guides/upgrade-to/v6.mdx Outdated
@Prayaksh

Copy link
Copy Markdown
Author

tried to change as suggested.

thanks!

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.

`Astro.url` is equivalent to doing `new URL(Astro.request.url)`.
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Since Astro v6, the pathname may be partially decoded during route normalization. This means `Astro.url.pathname` may differ from `new URL(Astro.request.url).pathname` for percent-encoded route segments.

It's not always the case, so maybe using "may" sounds better

@ArmandPhilippot ArmandPhilippot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update but, in addition to Ema suggestion, I see two issues:

  • configuration-reference.mdx contains unrelated changes
  • the upgrade guide section is misplaced:

Comment thread src/content/docs/en/guides/upgrade-to/v6.mdx Outdated
Comment thread src/content/docs/en/reference/configuration-reference.mdx Outdated
@Prayaksh Prayaksh force-pushed the fix/astro-url-runtime-docs branch from 440fed4 to 16481ea Compare May 30, 2026 05:55
@Prayaksh

Copy link
Copy Markdown
Author

Sorry for the confusion — my previous commit accidentally included an unrelated change. I've corrected the commit and updated the branch so the PR now only contains the intended documentation changes.

I also wasn't able to identify the source PR for this behavior change. If there's a specific PR number that should be referenced, please let me know.

@ArmandPhilippot ArmandPhilippot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is a breaking change, I don't think users want to know how to access the encoded path, but rather the decoded one (see my suggestions).

I'm not sure about the implementation PR, maybe Ema have more info on this.


### Changed: Route pathname normalization

<SourcePR number="???" title="???"/>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Ema could confirm as he has a better overall view of the changes that have taken place in the main repository, but I guess we can use the same PR as Percent-Encoding in routes.

Suggested change
<SourcePR number="???" title="???"/>
<SourcePR number="14306" title="feat: integrate vite environments"/>

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

<SourcePR number="???" title="???"/>

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ema suggestion should be applied here too:

Suggested change
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.
Since Astro v6, route pathnames may be partially decoded during route normalization. This means `Astro.url.pathname` may differ from `new URL(Astro.request.url).pathname` for percent-encoded route segments.

Comment thread src/content/docs/en/reference/api-reference.mdx Outdated
Prayaksh and others added 2 commits June 3, 2026 09:58
Co-authored-by: Armand Philippot <git@armand.philippot.eu>
Co-authored-by: Armand Philippot <git@armand.philippot.eu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

improve or update documentation Enhance / update existing documentation (e.g. add example, improve description, update for changes)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

URL Decoding in Dynamic Routes (SSR)

4 participants