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/lucky-cameras-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes an issue where Astro's default 404 route would incorrectly match routes containing "/404" in dev
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const DEFAULT_404_ROUTE: RouteData = {
component: DEFAULT_404_COMPONENT,
generate: () => '',
params: [],
pattern: /\/404/,
pattern: /^\/404\/?$/,
prerender: false,
pathname: '/404',
segments: [[{ content: '404', dynamic: false, spread: false }]],
Expand Down
8 changes: 8 additions & 0 deletions packages/astro/test/fixtures/user-route-priority/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@test/user-route-priority",
"version": "0.0.0",
"private": true,
"dependencies": {
"astro": "workspace:*"
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
const val = Number(Astro.params.number);
---
<html>
<head>
<title>Test app</title>
<style>body { font-size: 11px; }</style>
</head>
<body>
<h1>{ val }</h1>
</body>
</html>
40 changes: 40 additions & 0 deletions packages/astro/test/user-route-priority.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import assert from 'node:assert/strict';
import { before, describe, it } from 'node:test';
import { load as cheerioLoad } from 'cheerio';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';

describe('User routes have priority over internal routes', () => {
/** @type {import('./test-utils.js').Fixture} */
let fixture;

before(async () => {
const root = './fixtures/user-route-priority/';
fixture = await loadFixture({
root,
output: 'server',
adapter: testAdapter()
});
await fixture.build();
});

async function fetchHTML(path) {
const app = await fixture.loadTestAdapterApp();
const request = new Request('http://example.com' + path);
const response = await app.render(request);
const html = await response.text();
return html;
}

it("Page doesn't error with non-404 as number", async () => {
const html = await fetchHTML('/123');
const $ = cheerioLoad(html);
assert.equal($('h1').text(), '123');
});

it("Page doesn't error with 404 as number", async () => {
const html = await fetchHTML('/404');
const $ = cheerioLoad(html);
assert.equal($('h1').text(), '404');
});
});
7 changes: 6 additions & 1 deletion pnpm-lock.yaml

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