diff --git a/.changeset/dry-brooms-care.md b/.changeset/dry-brooms-care.md new file mode 100644 index 000000000..8318eba39 --- /dev/null +++ b/.changeset/dry-brooms-care.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix dynamic routes for sites with subpath diff --git a/packages/astro/src/core/dev/index.ts b/packages/astro/src/core/dev/index.ts index a424c43f8..6fb0e3e3e 100644 --- a/packages/astro/src/core/dev/index.ts +++ b/packages/astro/src/core/dev/index.ts @@ -319,7 +319,7 @@ export class AstroDevServer { logging: this.logging, mode: 'development', origin: this.origin, - pathname, + pathname: routePathname, route, routeCache: this.routeCache, viteServer: this.viteServer, diff --git a/packages/astro/test/dev-routing.test.js b/packages/astro/test/dev-routing.test.js index 2ed506335..1f5647935 100644 --- a/packages/astro/test/dev-routing.test.js +++ b/packages/astro/test/dev-routing.test.js @@ -32,6 +32,16 @@ describe('Development Routing', () => { const response = await fixture.fetch('/another'); expect(response.status).to.equal(200); }); + + it('200 when loading dynamic route', async () => { + const response = await fixture.fetch('/1'); + expect(response.status).to.equal(200); + }); + + it('500 when loading invalid dynamic route', async () => { + const response = await fixture.fetch('/2'); + expect(response.status).to.equal(500); + }); }); describe('No subpath used', () => { @@ -58,6 +68,16 @@ describe('Development Routing', () => { const response = await fixture.fetch('/another'); expect(response.status).to.equal(200); }); + + it('200 when loading dynamic route', async () => { + const response = await fixture.fetch('/1'); + expect(response.status).to.equal(200); + }); + + it('500 when loading invalid dynamic route', async () => { + const response = await fixture.fetch('/2'); + expect(response.status).to.equal(500); + }); }); describe('Subpath with trailing slash', () => { @@ -94,6 +114,16 @@ describe('Development Routing', () => { const response = await fixture.fetch('/blog/another/'); expect(response.status).to.equal(200); }); + + it('200 when loading dynamic route', async () => { + const response = await fixture.fetch('/blog/1/'); + expect(response.status).to.equal(200); + }); + + it('500 when loading invalid dynamic route', async () => { + const response = await fixture.fetch('/blog/2/'); + expect(response.status).to.equal(500); + }); }); describe('Subpath without trailing slash', () => { @@ -130,5 +160,15 @@ describe('Development Routing', () => { const response = await fixture.fetch('/blog/another/'); expect(response.status).to.equal(200); }); + + it('200 when loading dynamic route', async () => { + const response = await fixture.fetch('/blog/1/'); + expect(response.status).to.equal(200); + }); + + it('500 when loading invalid dynamic route', async () => { + const response = await fixture.fetch('/blog/2/'); + expect(response.status).to.equal(500); + }); }); }); diff --git a/packages/astro/test/fixtures/with-subpath-no-trailing-slash/src/pages/[id].astro b/packages/astro/test/fixtures/with-subpath-no-trailing-slash/src/pages/[id].astro new file mode 100644 index 000000000..b5dbc4307 --- /dev/null +++ b/packages/astro/test/fixtures/with-subpath-no-trailing-slash/src/pages/[id].astro @@ -0,0 +1,6 @@ +--- +export function getStaticPaths() { + return [{ params: { id: '1' } }]; +} +--- +

Post #1

diff --git a/packages/astro/test/fixtures/with-subpath-trailing-slash/src/pages/[id].astro b/packages/astro/test/fixtures/with-subpath-trailing-slash/src/pages/[id].astro new file mode 100644 index 000000000..b5dbc4307 --- /dev/null +++ b/packages/astro/test/fixtures/with-subpath-trailing-slash/src/pages/[id].astro @@ -0,0 +1,6 @@ +--- +export function getStaticPaths() { + return [{ params: { id: '1' } }]; +} +--- +

Post #1

diff --git a/packages/astro/test/fixtures/without-site-config/src/pages/[id].astro b/packages/astro/test/fixtures/without-site-config/src/pages/[id].astro new file mode 100644 index 000000000..b5dbc4307 --- /dev/null +++ b/packages/astro/test/fixtures/without-site-config/src/pages/[id].astro @@ -0,0 +1,6 @@ +--- +export function getStaticPaths() { + return [{ params: { id: '1' } }]; +} +--- +

Post #1

diff --git a/packages/astro/test/fixtures/without-subpath/src/pages/[id].astro b/packages/astro/test/fixtures/without-subpath/src/pages/[id].astro new file mode 100644 index 000000000..b5dbc4307 --- /dev/null +++ b/packages/astro/test/fixtures/without-subpath/src/pages/[id].astro @@ -0,0 +1,6 @@ +--- +export function getStaticPaths() { + return [{ params: { id: '1' } }]; +} +--- +

Post #1