routerMode: 'hash' navigation broken when using --base (regression in 52.16.0)
pending triage
**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**
1. Create a new Slidev project: `npm create slidev@latest`
2. Set `routerMode: 'hash'` in the frontmatter of `slides.md`
3. Build with a sub-directory base: `slidev build --base /my-base/slides/`
4. Serve the `dist/` folder and open the slides
5. 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:
```ts
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
2 条评论