mirror of
https://github.com/withastro/astro.git
synced 2025-03-31 23:31:30 -05:00
Fix leading slash creating incorrect conflict resolution between pages generated from static routes and rest parameters (#10607)
* test: added test-case failing like https://github.com/withastro/astro/issues/9103 * fix: replace leading `//` with `/` for generated static paths * fix: use stringifyParams()-function, removed JSON.stringify on string * test: align "/test/ing/"-title to other titles * ci: added changeset * test: updated test-name to more closely reflect the issue being tested * test: added test-case for dynamic route-param with leading slash * Update .changeset/tender-apples-lie.md --------- Co-authored-by: Frank <62514408+frank371ba@users.noreply.github.com> Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev> Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
This commit is contained in:
parent
416c4ac66d
commit
7327c6acb1
8 changed files with 44 additions and 2 deletions
5
.changeset/tender-apples-lie.md
Normal file
5
.changeset/tender-apples-lie.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Fixes an issue where a leading slash created incorrect conflict resolution between pages generated from static routes and catch-all dynamic routes
|
|
@ -51,6 +51,7 @@ import type {
|
|||
StylesheetAsset,
|
||||
} from './types.js';
|
||||
import { getTimeStat, shouldAppendForwardSlash } from './util.js';
|
||||
import {stringifyParams} from "../routing/params.js";
|
||||
|
||||
function createEntryURL(filePath: string, outFolder: URL) {
|
||||
return new URL('./' + filePath + `?time=${Date.now()}`, outFolder);
|
||||
|
@ -288,7 +289,7 @@ async function getPathsForRoute(
|
|||
paths = staticPaths
|
||||
.map((staticPath) => {
|
||||
try {
|
||||
return route.generate(staticPath.params);
|
||||
return stringifyParams(staticPath.params, route);
|
||||
} catch (e) {
|
||||
if (e instanceof TypeError) {
|
||||
throw getInvalidRouteSegmentError(e, route, staticPath);
|
||||
|
|
|
@ -18,5 +18,5 @@ export function stringifyParams(params: GetStaticPathsItem['params'], route: Rou
|
|||
return acc;
|
||||
}, {} as Params);
|
||||
|
||||
return JSON.stringify(route.generate(validatedParams));
|
||||
return route.generate(validatedParams);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,12 @@ describe('Dynamic route collision', () => {
|
|||
assert.equal($('h1').text(), 'Static About');
|
||||
});
|
||||
|
||||
it('Builds a static nested index when in conflict with a dynamic route with slug with leading slash', async () => {
|
||||
const html = await fixture.readFile('/test/index.html');
|
||||
const $ = cheerio.load(html);
|
||||
assert.equal($('h1').text(), 'Static Test');
|
||||
});
|
||||
|
||||
it('Builds a static route when in conflict with a spread route', async () => {
|
||||
const html = await fixture.readFile('/who/index.html');
|
||||
const $ = cheerio.load(html);
|
||||
|
@ -33,6 +39,12 @@ describe('Dynamic route collision', () => {
|
|||
assert.equal($('h1').text(), 'Static Tags Index');
|
||||
});
|
||||
|
||||
it('Builds a static nested index when in conflict with a spread route with slug with leading slash', async () => {
|
||||
const html = await fixture.readFile('/test/ing/index.html');
|
||||
const $ = cheerio.load(html);
|
||||
assert.equal($('h1').text(), 'Static TestIng');
|
||||
});
|
||||
|
||||
it('Builds a static root index when in conflict with a spread route', async () => {
|
||||
const html = await fixture.readFile('/index.html');
|
||||
const $ = cheerio.load(html);
|
||||
|
|
|
@ -13,6 +13,10 @@ export async function getStaticPaths() {
|
|||
slug: 'who',
|
||||
title: 'Rest Who We Are',
|
||||
},
|
||||
{
|
||||
slug: '/test/ing/',
|
||||
title: 'Rest TestIng',
|
||||
},
|
||||
];
|
||||
return pages.map(({ slug, title }) => {
|
||||
return {
|
||||
|
|
|
@ -9,6 +9,10 @@ export async function getStaticPaths() {
|
|||
page: 'blog',
|
||||
title: 'Dynamic Blog',
|
||||
},
|
||||
{
|
||||
page: '/test',
|
||||
title: 'Dynamic Test',
|
||||
},
|
||||
];
|
||||
return pages.map(({ page, title }) => {
|
||||
return {
|
||||
|
|
8
packages/astro/test/fixtures/dynamic-route-collision/src/pages/test.astro
vendored
Normal file
8
packages/astro/test/fixtures/dynamic-route-collision/src/pages/test.astro
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Static Test</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Static Test</h1>
|
||||
</body>
|
||||
</html>
|
8
packages/astro/test/fixtures/dynamic-route-collision/src/pages/test/ing.astro
vendored
Normal file
8
packages/astro/test/fixtures/dynamic-route-collision/src/pages/test/ing.astro
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Static TestIng</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Static TestIng</h1>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Reference in a new issue