Skip to content

Commit e4c26dc

Browse files
committed
Reverse the behaviour
1 parent c623c4a commit e4c26dc

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

packages/astro/src/core/app/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,12 @@ export class App {
209209
if (this.#manifest.assets.has(url.pathname)) return undefined;
210210
let pathname = this.#computePathnameFromDomain(request);
211211
if (!pathname) {
212-
pathname = prependForwardSlash(this.removeBase(url.pathname));
212+
pathname = this.removeBase(url.pathname)
213+
if(pathname !== '' || this.#manifest.base === '/') {
214+
pathname = prependForwardSlash(pathname);
215+
}
213216
}
214217
let routeData = matchRoute(decodeURI(pathname), this.#manifestData);
215-
216218
if (!routeData) return undefined;
217219
if (allowPrerenderedRoutes) {
218220
return routeData;

packages/astro/src/core/routing/manifest/pattern.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function getPattern(
3838
const trailing =
3939
addTrailingSlash && segments.length ? getTrailingSlashPattern(addTrailingSlash) : '$';
4040
let initial = '\\/';
41-
if (addTrailingSlash === 'never' && base !== '/' && pathname !== '') {
41+
if (addTrailingSlash === 'never' && base !== '/') {
4242
initial = '';
4343
}
4444
return new RegExp(`^${pathname || initial}${trailing}`);

packages/astro/src/vite-plugin-astro-server/base.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export function baseMiddleware(
3030

3131
if (pathname.startsWith(devRoot)) {
3232
req.url = url.replace(devRoot, devRootReplacement);
33-
req.url ||= '/';
3433
return next();
3534
}
3635

packages/astro/test/units/routing/manifest.test.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function assertRouteRelations(routes, relations) {
3737
}
3838

3939
describe('routing - createRoutesList', () => {
40-
it('using trailingSlash: "never" matches the index route when it contains a trailing slash', async () => {
40+
it('using trailingSlash: "never" does not match the index route when it contains a trailing slash', async () => {
4141
const fixture = await createFixture({
4242
'/src/pages/index.astro': `<h1>test</h1>`,
4343
});
@@ -51,9 +51,8 @@ describe('routing - createRoutesList', () => {
5151
settings,
5252
});
5353
const [{ pattern }] = manifest.routes;
54-
// Requesting `/` *should* match the index route, because that's what it sees when requesting `/search`.
55-
// If they've requested `/search/` this will have been caught by trailingSlashMiddleware
56-
assert.equal(pattern.test('/'), true);
54+
assert.equal(pattern.test(''), true);
55+
assert.equal(pattern.test('/'), false);
5756
});
5857

5958
it('endpoint routes are sorted before page routes', async () => {

0 commit comments

Comments
 (0)