From d3a714e003b431ec89e554d010dac679dcbe17d0 Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Thu, 26 Sep 2024 23:02:46 -0700 Subject: [PATCH] fix: 404 on refresh bug --- src/routes/+layout.ts | 3 +++ src/routes/post/{+page.ts => +page.server.ts} | 2 +- svelte.config.js | 8 +++++++- 3 files changed, 11 insertions(+), 2 deletions(-) rename src/routes/post/{+page.ts => +page.server.ts} (86%) diff --git a/src/routes/+layout.ts b/src/routes/+layout.ts index 189f71e..522d7b2 100644 --- a/src/routes/+layout.ts +++ b/src/routes/+layout.ts @@ -1 +1,4 @@ export const prerender = true; + +// Prevent page 404 on refresh +export const trailingSlash = 'always'; diff --git a/src/routes/post/+page.ts b/src/routes/post/+page.server.ts similarity index 86% rename from src/routes/post/+page.ts rename to src/routes/post/+page.server.ts index 088d555..283c681 100644 --- a/src/routes/post/+page.ts +++ b/src/routes/post/+page.server.ts @@ -7,7 +7,7 @@ export const load: PageLoad = async ({ params }) => { const allPosts = await Promise.all( iterablePostFiles.map(async ([pathMarkdown, resolver]) => { const { metadata } = await resolver(); - const pathPost = "post/" + pathMarkdown.slice(pathMarkdown.lastIndexOf("/") + 1, -".md".length); + const pathPost = pathMarkdown.slice(pathMarkdown.lastIndexOf("/") + 1, -".md".length); return { meta: { diff --git a/svelte.config.js b/svelte.config.js index 38c4409..10d220e 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -33,7 +33,13 @@ const config = { // adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list. // If your environment is not supported, or you settled on a specific environment, switch out the adapter. // See https://kit.svelte.dev/docs/adapters for more information about adapters. - adapter: adapter(), + adapter: adapter({ + pages: "build", + assets: "build", + fallback: null, + precompress: false, + trailingSlash: 'always', + }), alias: { $content: contentDir, "@/*": "./*",