From 6e7e95a730c785052f257d04b82a77f90bfc3b2a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 1 Jul 2026 13:23:31 +0000 Subject: [PATCH 1/4] Initial plan From 0b9245ac2de76bcdd89569adf4ff61bf4e33bfb7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 1 Jul 2026 13:25:59 +0000 Subject: [PATCH 2/4] fix: normalize Slidev router paths for standalone decks --- setup/main.ts | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/setup/main.ts b/setup/main.ts index f459aaa..bacc938 100644 --- a/setup/main.ts +++ b/setup/main.ts @@ -1,3 +1,34 @@ import { defineAppSetup } from "@slidev/types"; -export default defineAppSetup(() => {}); +export default defineAppSetup(({ router }) => { + if (typeof window === "undefined" || !router) return; + + const base: string = (router as any).options?.history?.base ?? ""; + const normalizedBase = base.endsWith("/") ? base.slice(0, -1) : base; + const baseWithoutLeadingSlash = normalizedBase.replace(/^\//, ""); + + if (!normalizedBase) return; + + const stripBase = (path: string) => { + if (path.startsWith(normalizedBase)) + return path.slice(normalizedBase.length) || "/"; + if (baseWithoutLeadingSlash && path.startsWith(baseWithoutLeadingSlash)) + return path.slice(baseWithoutLeadingSlash.length) || "/"; + return path; + }; + + const push = router.push.bind(router); + const replace = router.replace.bind(router); + + router.push = (to: any) => { + if (to?.path) return push({ ...to, path: stripBase(to.path) }); + if (typeof to === "string") return push(stripBase(to)); + return push(to); + }; + + router.replace = (to: any) => { + if (to?.path) return replace({ ...to, path: stripBase(to.path) }); + if (typeof to === "string") return replace(stripBase(to)); + return replace(to); + }; +}); From d250c3d37c8a756e2cec10eb658ac1b2a87c1d5d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 1 Jul 2026 13:27:14 +0000 Subject: [PATCH 3/4] refactor: type Slidev route normalization wrapper --- setup/main.ts | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/setup/main.ts b/setup/main.ts index bacc938..3f9256d 100644 --- a/setup/main.ts +++ b/setup/main.ts @@ -3,7 +3,15 @@ import { defineAppSetup } from "@slidev/types"; export default defineAppSetup(({ router }) => { if (typeof window === "undefined" || !router) return; - const base: string = (router as any).options?.history?.base ?? ""; + const base = ( + router as typeof router & { + options?: { + history?: { + base?: string; + }; + }; + } + ).options?.history?.base ?? ""; const normalizedBase = base.endsWith("/") ? base.slice(0, -1) : base; const baseWithoutLeadingSlash = normalizedBase.replace(/^\//, ""); @@ -17,18 +25,18 @@ export default defineAppSetup(({ router }) => { return path; }; - const push = router.push.bind(router); - const replace = router.replace.bind(router); + type NavigationTarget = Parameters[0]; + type NavigationMethod = (to: NavigationTarget) => ReturnType; - router.push = (to: any) => { - if (to?.path) return push({ ...to, path: stripBase(to.path) }); - if (typeof to === "string") return push(stripBase(to)); - return push(to); + const wrapNavigationMethod = (navigate: NavigationMethod): NavigationMethod => { + return (to) => { + if (typeof to === "string") return navigate(stripBase(to)); + if (to && typeof to === "object" && "path" in to && typeof to.path === "string") + return navigate({ ...to, path: stripBase(to.path) }); + return navigate(to); + }; }; - router.replace = (to: any) => { - if (to?.path) return replace({ ...to, path: stripBase(to.path) }); - if (typeof to === "string") return replace(stripBase(to)); - return replace(to); - }; + router.push = wrapNavigationMethod(router.push.bind(router) as NavigationMethod); + router.replace = wrapNavigationMethod(router.replace.bind(router) as NavigationMethod); }); From 24b9dc51a9dd946b00dc2238251ce67efbbe1d28 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 1 Jul 2026 13:28:15 +0000 Subject: [PATCH 4/4] fix: harden standalone Slidev route normalization --- setup/main.ts | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/setup/main.ts b/setup/main.ts index 3f9256d..12afd3e 100644 --- a/setup/main.ts +++ b/setup/main.ts @@ -3,24 +3,30 @@ import { defineAppSetup } from "@slidev/types"; export default defineAppSetup(({ router }) => { if (typeof window === "undefined" || !router) return; - const base = ( - router as typeof router & { - options?: { - history?: { - base?: string; - }; - }; - } - ).options?.history?.base ?? ""; + const routerOptions = + "options" in router + ? (router.options as + | { + history?: { + base?: string; + }; + } + | undefined) + : undefined; + const base = routerOptions?.history?.base ?? ""; const normalizedBase = base.endsWith("/") ? base.slice(0, -1) : base; const baseWithoutLeadingSlash = normalizedBase.replace(/^\//, ""); if (!normalizedBase) return; + const hasPathPrefix = (path: string, prefix: string) => + path.startsWith(prefix) && + (path.length === prefix.length || path[prefix.length] === "/"); + const stripBase = (path: string) => { - if (path.startsWith(normalizedBase)) + if (hasPathPrefix(path, normalizedBase)) return path.slice(normalizedBase.length) || "/"; - if (baseWithoutLeadingSlash && path.startsWith(baseWithoutLeadingSlash)) + if (baseWithoutLeadingSlash && hasPathPrefix(path, baseWithoutLeadingSlash)) return path.slice(baseWithoutLeadingSlash.length) || "/"; return path; };