0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-31 23:31:30 -05:00

Fix loading of non-index routes that end with index.html (#10979)

* Add test

* Fix alt pathname

* Add changeset
This commit is contained in:
Bryce Russell 2024-05-09 12:38:28 -05:00 committed by GitHub
parent 370b9f1612
commit 6fa89e84c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 15 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
"astro": patch
---
Fix loading of non-index routes that end with `index.html`

View file

@ -81,7 +81,10 @@ export async function matchRoute(
// Try without `.html` extensions or `index.html` in request URLs to mimic
// routing behavior in production builds. This supports both file and directory
// build formats, and is necessary based on how the manifest tracks build targets.
const altPathname = pathname.replace(/(?:index)?\.html$/, '');
const altPathname = pathname
.replace(/\/index\.html$/, '/')
.replace(/\.html$/, '');
if (altPathname !== pathname) {
return await matchRoute(altPathname, manifestData, pipeline);
}

View file

@ -321,6 +321,11 @@ describe('Development Routing', () => {
assert.equal(response.status, 200);
});
it('200 when loading /base-index.html', async () => {
const response = await fixture.fetch('/base-index.html');
assert.equal(response.status, 200);
});
it('200 when loading /', async () => {
const response = await fixture.fetch('/');
assert.equal(response.status, 200);

View file

@ -0,0 +1 @@
<div>testing</div>