navgo 6.0.8 → 6.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +27 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
scroll_to_hash,
|
|
13
13
|
validate_search,
|
|
14
14
|
} from './utils.js'
|
|
15
|
-
import
|
|
15
|
+
import * as svelte from 'svelte'
|
|
16
16
|
import { writable } from 'svelte/store'
|
|
17
17
|
export { v }
|
|
18
18
|
import { parse } from 'regexparam'
|
|
@@ -28,7 +28,7 @@ export default class Navgo {
|
|
|
28
28
|
preload_on_hover: true,
|
|
29
29
|
before_navigate: undefined,
|
|
30
30
|
after_navigate: undefined,
|
|
31
|
-
tick,
|
|
31
|
+
tick: svelte.tick,
|
|
32
32
|
scroll_to_top: true,
|
|
33
33
|
aria_current: false,
|
|
34
34
|
attach_to_window: true,
|
|
@@ -288,7 +288,12 @@ export default class Navgo {
|
|
|
288
288
|
ℹ('[🧭 navigate]', 'cancelled by before_route_leave during unload')
|
|
289
289
|
ev.preventDefault()
|
|
290
290
|
ev.returnValue = ''
|
|
291
|
+
return
|
|
291
292
|
}
|
|
293
|
+
|
|
294
|
+
try {
|
|
295
|
+
history.scrollRestoration = 'auto'
|
|
296
|
+
} catch {}
|
|
292
297
|
}
|
|
293
298
|
|
|
294
299
|
//
|
|
@@ -1134,6 +1139,8 @@ export default class Navgo {
|
|
|
1134
1139
|
|
|
1135
1140
|
// allow frameworks to flush DOM before scrolling
|
|
1136
1141
|
try {
|
|
1142
|
+
await svelte.settled?.()
|
|
1143
|
+
await this.#opts.tick?.()
|
|
1137
1144
|
await this.#opts.tick?.()
|
|
1138
1145
|
} catch (e) {
|
|
1139
1146
|
ℹ('[🧭 hooks]', 'tick threw', { err: e })
|
|
@@ -1382,7 +1389,6 @@ export default class Navgo {
|
|
|
1382
1389
|
if (initial) this.route.set({ ...this.#target(initial), search_params: {} })
|
|
1383
1390
|
|
|
1384
1391
|
const group_ids = new Map()
|
|
1385
|
-
|
|
1386
1392
|
function compile_routes(entries, stack = []) {
|
|
1387
1393
|
const out = []
|
|
1388
1394
|
for (const e of entries || []) {
|
|
@@ -1440,9 +1446,8 @@ export default class Navgo {
|
|
|
1440
1446
|
//
|
|
1441
1447
|
// Lifecycle hooks
|
|
1442
1448
|
//
|
|
1443
|
-
init() {
|
|
1444
|
-
|
|
1445
|
-
ℹ('[🧭 init]', 'attach listeners; scrollRestoration=manual')
|
|
1449
|
+
async init() {
|
|
1450
|
+
ℹ('[🧭 init]', 'attach listeners')
|
|
1446
1451
|
|
|
1447
1452
|
addEventListener('popstate', this.#on_popstate)
|
|
1448
1453
|
addEventListener('click', this.#click)
|
|
@@ -1475,7 +1480,11 @@ export default class Navgo {
|
|
|
1475
1480
|
|
|
1476
1481
|
ℹ('[🧭 init]', 'initial goto')
|
|
1477
1482
|
if (this.#opts.attach_to_window) window.navgo = this
|
|
1478
|
-
|
|
1483
|
+
await this.goto()
|
|
1484
|
+
try {
|
|
1485
|
+
history.scrollRestoration = 'manual'
|
|
1486
|
+
ℹ('[🧭 init]', 'scrollRestoration=manual')
|
|
1487
|
+
} catch {}
|
|
1479
1488
|
}
|
|
1480
1489
|
destroy() {
|
|
1481
1490
|
removeEventListener('popstate', this.#on_popstate)
|
|
@@ -1500,17 +1509,27 @@ export default class Navgo {
|
|
|
1500
1509
|
const hash = location.hash
|
|
1501
1510
|
const t = ctx?.type || ctx?.event?.type
|
|
1502
1511
|
requestAnimationFrame(() => {
|
|
1503
|
-
// 0) Initial (first) navigation: prefer restoring session scroll
|
|
1512
|
+
// 0) Initial (first) navigation: prefer restoring session scroll,
|
|
1513
|
+
// otherwise preserve whatever the browser already did for the SSR document.
|
|
1504
1514
|
const is_initial = ctx && 'from' in ctx ? ctx.from == null : !t
|
|
1505
1515
|
if (is_initial) {
|
|
1506
1516
|
try {
|
|
1507
1517
|
const k = `__navgo_scroll:${location.href}`
|
|
1508
1518
|
const { x, y } = JSON.parse(sessionStorage.getItem(k))
|
|
1509
1519
|
sessionStorage.removeItem(k)
|
|
1520
|
+
try {
|
|
1521
|
+
history.scrollRestoration = 'manual'
|
|
1522
|
+
} catch {}
|
|
1510
1523
|
scrollTo(x, y)
|
|
1511
1524
|
ℹ('[🧭 scroll]', 'restore session', { x, y })
|
|
1512
1525
|
return
|
|
1513
1526
|
} catch {}
|
|
1527
|
+
if (hash && scroll_to_hash(hash)) {
|
|
1528
|
+
ℹ('[🧭 scroll]', 'initial hash')
|
|
1529
|
+
return
|
|
1530
|
+
}
|
|
1531
|
+
ℹ('[🧭 scroll]', 'initial preserve')
|
|
1532
|
+
return
|
|
1514
1533
|
}
|
|
1515
1534
|
// 1) On back/forward, restore saved position if available
|
|
1516
1535
|
if (t === 'popstate') {
|