summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/fluffy-otters-guess.md5
-rw-r--r--packages/astro/e2e/solid-recurse.test.js2
-rw-r--r--packages/astro/src/core/build/generate.ts2
-rw-r--r--packages/astro/src/core/routing/manifest/generator.ts6
-rw-r--r--packages/astro/test/astro-get-static-paths.test.js22
-rw-r--r--packages/astro/test/fixtures/astro-get-static-paths/src/pages/food/[name].astro26
6 files changed, 60 insertions, 3 deletions
diff --git a/.changeset/fluffy-otters-guess.md b/.changeset/fluffy-otters-guess.md
new file mode 100644
index 000000000..e170e718c
--- /dev/null
+++ b/.changeset/fluffy-otters-guess.md
@@ -0,0 +1,5 @@
+---
+'astro': patch
+---
+
+Prevents automatic trailingSlash appending on getStaticPaths produced pages
diff --git a/packages/astro/e2e/solid-recurse.test.js b/packages/astro/e2e/solid-recurse.test.js
index 77f5b2833..c7ce0ebca 100644
--- a/packages/astro/e2e/solid-recurse.test.js
+++ b/packages/astro/e2e/solid-recurse.test.js
@@ -15,7 +15,7 @@ test.afterEach(async () => {
test.describe('Recursive elements with Solid', () => {
test('Counter', async ({ astro, page }) => {
- await page.goto(astro.resolveUrl('/'));
+ await page.goto('/');
const wrapper = page.locator('#case1');
await expect(wrapper, 'component is visible').toBeVisible();
diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts
index dd500e348..cced45479 100644
--- a/packages/astro/src/core/build/generate.ts
+++ b/packages/astro/src/core/build/generate.ts
@@ -245,7 +245,7 @@ interface GeneratePathOptions {
}
function addPageName(pathname: string, opts: StaticBuildOptions): void {
- opts.pageNames.push(pathname.replace(/\/?$/, '/').replace(/^\//, ''));
+ opts.pageNames.push(pathname.replace(/^\//, ''));
}
async function generatePath(
diff --git a/packages/astro/src/core/routing/manifest/generator.ts b/packages/astro/src/core/routing/manifest/generator.ts
index 27039950c..300dabd17 100644
--- a/packages/astro/src/core/routing/manifest/generator.ts
+++ b/packages/astro/src/core/routing/manifest/generator.ts
@@ -28,7 +28,11 @@ export function getRouteGenerator(
})
.join('');
- const trailing = addTrailingSlash !== 'never' && segments.length ? '/' : '';
+ // Unless trailingSlash config is set to 'always', don't automatically append it.
+ let trailing: '/' | '' = '';
+ if(addTrailingSlash === 'always' && segments.length) {
+ trailing = '/';
+ }
const toPath = compile(template + trailing);
return toPath;
}
diff --git a/packages/astro/test/astro-get-static-paths.test.js b/packages/astro/test/astro-get-static-paths.test.js
index bfc01d2f5..8a0fcca58 100644
--- a/packages/astro/test/astro-get-static-paths.test.js
+++ b/packages/astro/test/astro-get-static-paths.test.js
@@ -150,3 +150,25 @@ describe('getStaticPaths - numeric route params', () => {
}
});
});
+
+describe('getStaticPaths - Astro.url', () => {
+ /** @type {import('./test-utils').Fixture} */
+ let fixture;
+ before(async () => {
+ // reset the flag used by [...calledTwiceTest].astro between each test
+ globalThis.isCalledOnce = false;
+
+ fixture = await loadFixture({
+ root: './fixtures/astro-get-static-paths/',
+ site: 'https://mysite.dev/',
+ });
+ await fixture.build();
+ });
+
+ it('Sets the current pathname', async () => {
+ const html = await fixture.readFile('/food/tacos/index.html');
+ const $ = cheerio.load(html);
+
+ expect($('#url').text()).to.equal('/food/tacos');
+ });
+});
diff --git a/packages/astro/test/fixtures/astro-get-static-paths/src/pages/food/[name].astro b/packages/astro/test/fixtures/astro-get-static-paths/src/pages/food/[name].astro
new file mode 100644
index 000000000..f0c68e681
--- /dev/null
+++ b/packages/astro/test/fixtures/astro-get-static-paths/src/pages/food/[name].astro
@@ -0,0 +1,26 @@
+---
+export async function getStaticPaths() {
+ return [
+ {
+ params: { name: 'tacos' },
+ },
+ {
+ params: { name: 'potatoes' },
+ },
+ {
+ params: { name: 'spaghetti' }
+ }
+ ]
+}
+---
+
+<html lang="en">
+ <head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width" />
+ <title>Food</title>
+ </head>
+ <body>
+ <p id="url">{ Astro.url.pathname }</p>
+ </body>
+</html>