Skip to content

Commit

Permalink
Fix dynamic routes for sites with subpath (#2299)
Browse files Browse the repository at this point in the history
  • Loading branch information
tadeuzagallo committed Jan 4, 2022
1 parent c80c7f6 commit 5fbdd56
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/dry-brooms-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix dynamic routes for sites with subpath
2 changes: 1 addition & 1 deletion packages/astro/src/core/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
40 changes: 40 additions & 0 deletions packages/astro/test/dev-routing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
export function getStaticPaths() {
return [{ params: { id: '1' } }];
}
---
<h1>Post #1</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
export function getStaticPaths() {
return [{ params: { id: '1' } }];
}
---
<h1>Post #1</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
export function getStaticPaths() {
return [{ params: { id: '1' } }];
}
---
<h1>Post #1</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
export function getStaticPaths() {
return [{ params: { id: '1' } }];
}
---
<h1>Post #1</h1>

0 comments on commit 5fbdd56

Please sign in to comment.