Skip to content

Commit 27a9888

Browse files
authored
render fallback page regardless of trailingSlash - fixes #4340 (#4351)
1 parent 04dd532 commit 27a9888

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

.changeset/few-carrots-sell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
Populate fallback page when trailingSlash is "always"

packages/kit/src/runtime/server/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function respond(request, options, state) {
1818

1919
const normalized = normalize_path(url.pathname, options.trailing_slash);
2020

21-
if (normalized !== url.pathname) {
21+
if (normalized !== url.pathname && !state.prerender?.fallback) {
2222
return new Response(undefined, {
2323
status: 301,
2424
headers: {

packages/kit/test/prerendering/options/svelte.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import adapter from '../../../../adapter-static/index.js';
44
/** @type {import('@sveltejs/kit').Config} */
55
const config = {
66
kit: {
7-
adapter: adapter(),
7+
adapter: adapter({
8+
fallback: '200.html'
9+
}),
810

911
csp: {
1012
directives: {

packages/kit/test/prerendering/options/test/test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,10 @@ test('does not copy `public` into `_app`', () => {
3131
assert.ok(!fs.existsSync(`${build}/_app/robots.txt`));
3232
});
3333

34+
// https://github.com/sveltejs/kit/issues/4340
35+
test('populates fallback 200.html file', () => {
36+
const content = read('200.html');
37+
assert.ok(content !== '');
38+
});
39+
3440
test.run();

0 commit comments

Comments
 (0)