-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
feat(astro): Add fallbackRoutes to astro:routes:resolved's return type and include them in the sitemap integration
#15455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
matthewp
merged 5 commits into
withastro:main
from
AhmadYasser1:fix/sitemap-i18n-fallback
Mar 25, 2026
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c45c0fd
fix(sitemap): include i18n fallback pages in generated sitemap
AhmadYasser1 e27cc47
Merge remote-tracking branch 'origin/main' into fix/sitemap-i18n-fall…
Princesseuh 1eb09fd
feat: rework implementation
Princesseuh 4cdc487
Merge branch 'main' into fix/sitemap-i18n-fallback
Princesseuh 4474dab
add missing full stop
yanthomasdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@astrojs/sitemap': patch | ||
| --- | ||
|
|
||
| Fixes i18n fallback pages missing from the generated sitemap when using `fallbackType: 'rewrite'` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| --- | ||
| 'astro': minor | ||
| --- | ||
|
|
||
| Adds `fallbackRoutes` to the `IntegrationResolvedRoute` type, exposing i18n fallback routes to integrations via the `astro:routes:resolved` hook for projects using `fallbackType: 'rewrite'`. | ||
|
|
||
| This allows integrations such as the sitemap integration to properly include generated fallback routes in their output. | ||
|
|
||
| ```js | ||
| { | ||
| 'astro:routes:resolved': ({ routes }) => { | ||
| for (const route of routes) { | ||
| for (const fallback of route.fallbackRoutes) { | ||
| console.log(fallback.pathname) // e.g. /fr/about/ | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/integrations/sitemap/test/fixtures/i18n-fallback/astro.config.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import sitemap from '@astrojs/sitemap'; | ||
| import { defineConfig } from 'astro/config'; | ||
|
|
||
| export default defineConfig({ | ||
| integrations: [sitemap()], | ||
| site: 'http://example.com', | ||
| i18n: { | ||
| locales: ['en', 'fr'], | ||
| defaultLocale: 'en', | ||
| fallback: { | ||
| fr: 'en', | ||
| }, | ||
| routing: { | ||
| prefixDefaultLocale: false, | ||
| fallbackType: 'rewrite', | ||
| }, | ||
| }, | ||
| }); |
9 changes: 9 additions & 0 deletions
9
packages/integrations/sitemap/test/fixtures/i18n-fallback/package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "name": "@test/sitemap-i18n-fallback", | ||
| "version": "0.0.0", | ||
| "private": true, | ||
| "dependencies": { | ||
| "astro": "workspace:*", | ||
| "@astrojs/sitemap": "workspace:*" | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
packages/integrations/sitemap/test/fixtures/i18n-fallback/src/pages/about.astro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| --- | ||
| <html> | ||
| <head><title>About</title></head> | ||
| <body><h1>About</h1></body> | ||
| </html> |
6 changes: 6 additions & 0 deletions
6
packages/integrations/sitemap/test/fixtures/i18n-fallback/src/pages/index.astro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| --- | ||
| <html> | ||
| <head><title>Home</title></head> | ||
| <body><h1>Home</h1></body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { before, describe, it } from 'node:test'; | ||
| import { loadFixture, readXML } from './test-utils.js'; | ||
|
|
||
| describe('i18n fallback', () => { | ||
| /** @type {import('./test-utils.js').Fixture} */ | ||
| let fixture; | ||
| /** @type {string[]} */ | ||
| let urls; | ||
|
|
||
| before(async () => { | ||
| fixture = await loadFixture({ | ||
| root: './fixtures/i18n-fallback/', | ||
| }); | ||
| await fixture.build(); | ||
| const data = await readXML(fixture.readFile('/sitemap-0.xml')); | ||
| urls = data.urlset.url.map((url) => url.loc[0]); | ||
| }); | ||
|
|
||
| it('includes default locale pages', async () => { | ||
| assert.equal(urls.includes('http://example.com/'), true); | ||
| assert.equal(urls.includes('http://example.com/about/'), true); | ||
| }); | ||
|
|
||
| it('includes fallback locale pages', async () => { | ||
| assert.equal(urls.includes('http://example.com/fr/'), true); | ||
| assert.equal(urls.includes('http://example.com/fr/about/'), true); | ||
| }); | ||
| }); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.