Fix dynamic routes for sites with subpath (#2299)
This commit is contained in:
parent
c80c7f677c
commit
5fbdd56f15
7 changed files with 70 additions and 1 deletions
5
.changeset/dry-brooms-care.md
Normal file
5
.changeset/dry-brooms-care.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix dynamic routes for sites with subpath
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
6
packages/astro/test/fixtures/with-subpath-no-trailing-slash/src/pages/[id].astro
vendored
Normal file
6
packages/astro/test/fixtures/with-subpath-no-trailing-slash/src/pages/[id].astro
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
export function getStaticPaths() {
|
||||
return [{ params: { id: '1' } }];
|
||||
}
|
||||
---
|
||||
<h1>Post #1</h1>
|
6
packages/astro/test/fixtures/with-subpath-trailing-slash/src/pages/[id].astro
vendored
Normal file
6
packages/astro/test/fixtures/with-subpath-trailing-slash/src/pages/[id].astro
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
export function getStaticPaths() {
|
||||
return [{ params: { id: '1' } }];
|
||||
}
|
||||
---
|
||||
<h1>Post #1</h1>
|
6
packages/astro/test/fixtures/without-site-config/src/pages/[id].astro
vendored
Normal file
6
packages/astro/test/fixtures/without-site-config/src/pages/[id].astro
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
export function getStaticPaths() {
|
||||
return [{ params: { id: '1' } }];
|
||||
}
|
||||
---
|
||||
<h1>Post #1</h1>
|
6
packages/astro/test/fixtures/without-subpath/src/pages/[id].astro
vendored
Normal file
6
packages/astro/test/fixtures/without-subpath/src/pages/[id].astro
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
export function getStaticPaths() {
|
||||
return [{ params: { id: '1' } }];
|
||||
}
|
||||
---
|
||||
<h1>Post #1</h1>
|
Loading…
Reference in a new issue