fix(deck): deep links land on the right slide without a flash
Seed the slide index from the URL hash synchronously at setup instead of after mount, so opening …/#/7 renders slide 7 immediately (no flash of slide 1 and no on-load transition). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
10b3551668
commit
49ad78360a
1 changed files with 3 additions and 2 deletions
|
|
@ -12,7 +12,9 @@ export function useDeck(total: number) {
|
|||
return m ? clamp(parseInt(m[1], 10) - 1) : 0
|
||||
}
|
||||
|
||||
const index = ref(0)
|
||||
// seed from the hash synchronously so deep links (…/#/7) land on the right
|
||||
// slide at first paint — no flash of slide 1 and no on-load transition.
|
||||
const index = ref(readHash())
|
||||
const direction = ref<1 | -1>(1)
|
||||
|
||||
function goto(n: number) {
|
||||
|
|
@ -43,7 +45,6 @@ export function useDeck(total: number) {
|
|||
}
|
||||
|
||||
onMounted(() => {
|
||||
index.value = readHash()
|
||||
if (!window.location.hash) window.location.hash = '#/1'
|
||||
window.addEventListener('keydown', onKey)
|
||||
window.addEventListener('hashchange', onHash)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue