Describe the bug
Since 52.16.0, navigating between slides is broken when using routerMode: 'hash' and deploying to a sub-directory with --base. The fix from #2562 (prepending import.meta.env.BASE_URL to the route path in getSlidePath) assumes routerMode: 'history', but breaks 'hash' mode.
With createWebHashHistory, Vue Router does not strip the base from paths passed to router.push(). The full base gets prepended to the hash fragment, producing an unmatchable route:
# Expected
https://example.com/my-base/slides/#/4
# Actual (52.16.0 with routerMode: 'hash')
https://example.com/my-base/slides/#/my-base/slides/4
Minimal reproduction
- Create a new Slidev project:
npm create slidev@latest
- Set
routerMode: 'hash' in the frontmatter of slides.md
- Build with a sub-directory base:
slidev build --base /my-base/slides/
- Serve the
dist/ folder and open the slides
- Navigate to the next slide — the URL becomes
#/my-base/slides/2 instead of #/2, resulting in a 404/blank page
Root cause
packages/client/logic/slides.ts — getSlidePath now returns:
return `${import.meta.env.BASE_URL}${path}` // e.g. "/my-base/slides/2"
This path is passed directly to router.push({ path: ... }). With createWebHistory the router strips the base and this works correctly. With createWebHashHistory the base is not stripped, so the full string lands in the hash fragment as an unresolvable route.
Environment
- Slidev version: 52.16.0 (regression from 52.14.2)
- Browser: Chrome / Firefox
- OS: Linux
Describe the bug
Since
52.16.0, navigating between slides is broken when usingrouterMode: 'hash'and deploying to a sub-directory with--base. The fix from #2562 (prependingimport.meta.env.BASE_URLto the route path ingetSlidePath) assumesrouterMode: 'history', but breaks'hash'mode.With
createWebHashHistory, Vue Router does not strip the base from paths passed torouter.push(). The full base gets prepended to the hash fragment, producing an unmatchable route:Minimal reproduction
npm create slidev@latestrouterMode: 'hash'in the frontmatter ofslides.mdslidev build --base /my-base/slides/dist/folder and open the slides#/my-base/slides/2instead of#/2, resulting in a 404/blank pageRoot cause
packages/client/logic/slides.ts—getSlidePathnow returns:This path is passed directly to
router.push({ path: ... }). WithcreateWebHistorythe router strips the base and this works correctly. WithcreateWebHashHistorythe base is not stripped, so the full string lands in the hash fragment as an unresolvable route.Environment