Skip to content

Commit

Permalink
Fix loading of non-index routes that end with index.html (#10979)
Browse files Browse the repository at this point in the history
* Add test

* Fix alt pathname

* Add changeset
  • Loading branch information
BryceRussell committed May 9, 2024
1 parent 370b9f1 commit 6fa89e8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tiny-dodos-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Fix loading of non-index routes that end with `index.html`
5 changes: 4 additions & 1 deletion packages/astro/src/vite-plugin-astro-server/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/astro/test/dev-routing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>testing</div>

0 comments on commit 6fa89e8

Please sign in to comment.