0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-30 22:03:56 -05:00

Fix dynamic routes for sites with subpath (#2299)

This commit is contained in:
Tadeu Zagallo 2022-01-04 19:22:06 +01:00 committed by GitHub
parent c80c7f677c
commit 5fbdd56f15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 70 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix dynamic routes for sites with subpath

View file

@ -319,7 +319,7 @@ export class AstroDevServer {
logging: this.logging, logging: this.logging,
mode: 'development', mode: 'development',
origin: this.origin, origin: this.origin,
pathname, pathname: routePathname,
route, route,
routeCache: this.routeCache, routeCache: this.routeCache,
viteServer: this.viteServer, viteServer: this.viteServer,

View file

@ -32,6 +32,16 @@ describe('Development Routing', () => {
const response = await fixture.fetch('/another'); const response = await fixture.fetch('/another');
expect(response.status).to.equal(200); 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', () => { describe('No subpath used', () => {
@ -58,6 +68,16 @@ describe('Development Routing', () => {
const response = await fixture.fetch('/another'); const response = await fixture.fetch('/another');
expect(response.status).to.equal(200); 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', () => { describe('Subpath with trailing slash', () => {
@ -94,6 +114,16 @@ describe('Development Routing', () => {
const response = await fixture.fetch('/blog/another/'); const response = await fixture.fetch('/blog/another/');
expect(response.status).to.equal(200); 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', () => { describe('Subpath without trailing slash', () => {
@ -130,5 +160,15 @@ describe('Development Routing', () => {
const response = await fixture.fetch('/blog/another/'); const response = await fixture.fetch('/blog/another/');
expect(response.status).to.equal(200); 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);
});
}); });
}); });

View file

@ -0,0 +1,6 @@
---
export function getStaticPaths() {
return [{ params: { id: '1' } }];
}
---
<h1>Post #1</h1>

View file

@ -0,0 +1,6 @@
---
export function getStaticPaths() {
return [{ params: { id: '1' } }];
}
---
<h1>Post #1</h1>

View file

@ -0,0 +1,6 @@
---
export function getStaticPaths() {
return [{ params: { id: '1' } }];
}
---
<h1>Post #1</h1>

View file

@ -0,0 +1,6 @@
---
export function getStaticPaths() {
return [{ params: { id: '1' } }];
}
---
<h1>Post #1</h1>