Skip to content

docs: add experimental advanced routing reference page#13792

Open
matthewp wants to merge 24 commits intomainfrom
advanced-routing
Open

docs: add experimental advanced routing reference page#13792
matthewp wants to merge 24 commits intomainfrom
advanced-routing

Conversation

@matthewp
Copy link
Copy Markdown
Contributor

Description (required)

Documents the upcoming experimental.advancedRouting flag.

For Astro version: 6.2. See astro PR #16366.

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 27, 2026

Deploy Preview for astro-docs-2 ready!

Name Link
🔨 Latest commit 571ef48
🔍 Latest deploy log https://app.netlify.com/projects/astro-docs-2/deploys/69f1233ec9c5a400080a10eb
😎 Deploy Preview https://deploy-preview-13792--astro-docs-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@astrobot-houston
Copy link
Copy Markdown
Contributor

astrobot-houston commented Apr 27, 2026

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/reference/experimental-flags/advanced-routing.mdx Localization added, will be marked as complete.
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.

Comment thread src/content/docs/en/reference/experimental-flags/advanced-routing.mdx Outdated
Copy link
Copy Markdown
Member

@ArmandPhilippot ArmandPhilippot left a comment

Choose a reason for hiding this comment

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

Thanks Matthew, the wording looks good to me! No suggestions to improve that, only for the formatting:

  • We usually don't put the arguments in the headings (ie. middleware() instead of middleware(state, next)). This helps make the links easier to parse when sharing them: #middleware instead of #middlewarestate-next
  • I think an API block for the methods is also helpful since some of them have different arguments or different return types.

I also noticed a few em dashes. We usually don't use them in docs. I don't know if we want to stay consistent with this or not. I don't have a strong opinion.

Question: Do we need a section for ContextProvider?

I see that the FetchState types often refer to create and finalize. Maybe it would be helpful to document it so we can link to ContextProvider.create() and ContextProvider.finalize(). I think this helps users navigate easily to between related sections.

Comment thread src/content/docs/en/reference/experimental-flags/advanced-routing.mdx Outdated
Comment thread src/content/docs/en/reference/experimental-flags/advanced-routing.mdx Outdated
Comment thread src/content/docs/en/reference/experimental-flags/advanced-routing.mdx Outdated
Comment thread src/content/docs/en/reference/experimental-flags/advanced-routing.mdx Outdated
Comment thread src/content/docs/en/reference/experimental-flags/advanced-routing.mdx Outdated
Comment thread src/content/docs/en/reference/experimental-flags/advanced-routing.mdx Outdated
Comment thread src/content/docs/en/reference/experimental-flags/advanced-routing.mdx Outdated
Comment thread src/content/docs/en/reference/experimental-flags/advanced-routing.mdx Outdated
Comment thread src/content/docs/en/reference/experimental-flags/advanced-routing.mdx Outdated
Comment thread src/content/docs/en/reference/experimental-flags/advanced-routing.mdx Outdated
matthewp and others added 7 commits April 28, 2026 16:38
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
Comment thread src/content/docs/en/reference/experimental-flags/advanced-routing.mdx Outdated
matthewp and others added 12 commits April 28, 2026 16:56
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
…ing.mdx

Co-authored-by: Armand Philippot <git@armand.philippot.eu>
Copy link
Copy Markdown
Member

@yanthomasdev yanthomasdev left a comment

Choose a reason for hiding this comment

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

Thanks @matthewp, just adding a few suggestions to remove all these emdashes that are not necessary, and then LGTM


The main benefit of advanced routing is the ability to insert custom logic anywhere in the request pipeline. You can run code before Astro touches the request, between pipeline stages, or after the response is produced.

The [`astro()` handler](#astro) is the simplest way to add pre- or post-processing around the full pipeline. When you need to insert logic *between* specific stages — for example, running custom code after actions but before page rendering — compose the individual handlers instead:
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.

I'll say we should keep it consistent without emdashes.

Suggested change
The [`astro()` handler](#astro) is the simplest way to add pre- or post-processing around the full pipeline. When you need to insert logic *between* specific stages — for example, running custom code after actions but before page rendering compose the individual handlers instead:
The [`astro()` handler](#astro) is the simplest way to add pre- or post-processing around the full pipeline. When you need to insert logic *between* specific stages, such as running custom code after actions but before page rendering, compose the individual handlers instead:


If no `src/app.ts` file exists (or `advancedRouting` is not enabled), Astro uses its built-in pipeline, which runs all features automatically.

### Using `astro()` — the simplest approach
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.

Safe to remove the subheading of the subheading 😅

Suggested change
### Using `astro()` — the simplest approach
### Using `astro()`

async fetch(request: Request): Promise<Response> {
const state = new FetchState(request);

// Custom pre-processing — runs before any Astro handler
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
// Custom pre-processing runs before any Astro handler
// Custom pre-processing, runs before any Astro handler


const response = await astro(state);

// Custom post-processing — runs after Astro renders
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
// Custom post-processing runs after Astro renders
// Custom post-processing, runs after Astro renders

};
```

For many use cases — adding auth guards, request logging, custom headers — `astro()` is all you need.
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
For many use casesadding auth guards, request logging, custom headers `astro()` is all you need.
For many use cases, such as adding auth guards, request logging, and custom headers, `astro()` is all you need.

**Type:** <code>(state: <a href="#fetchstate">FetchState</a>) => Promise\<Response\></code>
</p>

Dispatches the request to the matched Astro route (page, endpoint, or fallback). This is the core rendering handler — most custom pipelines will include it.
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
Dispatches the request to the matched Astro route (page, endpoint, or fallback). This is the core rendering handler most custom pipelines will include it.
Dispatches the request to the matched Astro route (page, endpoint, or fallback). This is the core rendering handler, and most custom pipelines will include it.

**Type:** <code>(state: <a href="#fetchstate">FetchState</a>, next: (state: FetchState) => Promise\<Response\>) => Promise\<Response\></code>
</p>

Runs Astro's middleware chain (from `src/middleware.ts`). The `next` callback is called at the bottom of the chain to produce the response — typically by calling `pages()`:
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
Runs Astro's middleware chain (from `src/middleware.ts`). The `next` callback is called at the bottom of the chain to produce the response typically by calling `pages()`:
Runs Astro's middleware chain (from `src/middleware.ts`). The `next` callback is called at the bottom of the chain to produce the response, typically by calling `pages()`:

@ArmandPhilippot ArmandPhilippot added the minor-release For the next minor release; in the milestone, "merge queue" = approved for merging on release day. label May 1, 2026
@ArmandPhilippot ArmandPhilippot added this to the 6.3 milestone May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

minor-release For the next minor release; in the milestone, "merge queue" = approved for merging on release day.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants