diff options
author | 2022-01-04 19:22:06 +0100 | |
---|---|---|
committer | 2022-01-04 13:22:06 -0500 | |
commit | 5fbdd56f157f58d9d768f9d5388340aaa316da81 (patch) | |
tree | a385f487f4f8703a9e747accc99ec9c6bd16ab99 | |
parent | c80c7f677c8ba42efdbd399fd5bf9cf3c191856f (diff) | |
download | astro-5fbdd56f157f58d9d768f9d5388340aaa316da81.tar.gz astro-5fbdd56f157f58d9d768f9d5388340aaa316da81.tar.zst astro-5fbdd56f157f58d9d768f9d5388340aaa316da81.zip |
Fix dynamic routes for sites with subpath (#2299)
7 files changed, 70 insertions, 1 deletions
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' } }]; +} +--- +<h1>Post #1</h1> 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' } }]; +} +--- +<h1>Post #1</h1> 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' } }]; +} +--- +<h1>Post #1</h1> 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' } }]; +} +--- +<h1>Post #1</h1> |