Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit c8bea64

Browse files
committed
implement no scroll state
1 parent ff24877 commit c8bea64

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/runtime/index.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,17 @@ function prepare_page(target: Target): Promise<{
292292
});
293293
}
294294

295-
async function navigate(target: Target, id: number): Promise<any> {
295+
async function navigate(target: Target, id: number, noscroll = false): Promise<any> {
296296
if (id) {
297297
// popstate or initial navigation
298298
cid = id;
299299
} else {
300300
// clicked on a link. preserve scroll state
301-
scroll_history[cid] = scroll_state();
301+
const scrollState = scroll_state()
302+
scroll_history[cid] = scrollState;
302303

303304
id = cid = ++uid;
304-
scroll_history[cid] = { x: 0, y: 0 };
305+
scroll_history[cid] = noscroll ? scrollState : { x: 0, y: 0 };
305306
}
306307

307308
cid = id;
@@ -362,8 +363,9 @@ function handle_click(event: MouseEvent) {
362363
if (url.pathname === window.location.pathname && url.search === window.location.search) return;
363364

364365
const target = select_route(url);
366+
const hasNoscroll = a.hasAttribute('sapper-noscroll')
365367
if (target) {
366-
navigate(target, null);
368+
navigate(target, null, hasNoscroll);
367369
event.preventDefault();
368370
history.pushState({ id: cid }, '', url.href);
369371
}

0 commit comments

Comments
 (0)