Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/orange-cloths-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes a regression where using `next('/')` didn't correctly return the requested route.
2 changes: 1 addition & 1 deletion packages/astro/src/core/routing/rewrite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function findRouteToRewrite({
}

// Convert '/' to '' for trailingSlash: 'never'
if (pathname === '/' && !shouldAppendSlash) {
if (pathname === '/' && base !== '/' && !shouldAppendSlash) {
pathname = '';
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { defineConfig } from 'astro/config';

// https://astro.build/config
export default defineConfig({
base: '',
trailingSlash: 'never',
output: 'server'
});
8 changes: 8 additions & 0 deletions packages/astro/test/fixtures/rewrite-issue-13633/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@test/rewrite-issue13633",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const onRequest = async (ctx, next) => {
const response = await next('/');
return response;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
---

<html lang="en">
<head>
<title>About page</title>
</head>
<body>
<h1>About page</h1>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
---

<html lang="en">
<head>
<title>Index page</title>
</head>
<body>
<h1>Index page</h1>
</body>
</html>
25 changes: 25 additions & 0 deletions packages/astro/test/rewrite.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,3 +728,28 @@ describe('Runtime error in SSR, custom 500', () => {
assert.equal($('h1').text(), 'Expected http status of index page is 200');
});
});

describe('Issue 13633', async () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
let devServer;
before(async () => {
fixture = await loadFixture({
root: './fixtures/rewrite-issue-13633/',
output: 'server',
adapter: testAdapter(),
});
devServer = await fixture.startDevServer();
});

after(async () => {
await devServer.stop();
});

it('should correctly rewrite to be homepage', async () => {
const html = await fixture.fetch('/foo').then((res) => res.text());
const $ = cheerioLoad(html);

assert.equal($('h1').text(), 'Index page');
});
});
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.