mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-19 05:45:27 +00:00
minor tweaks
This commit is contained in:
@@ -106,17 +106,18 @@ export function scroll_state() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function navigate(target: Target, id: number, has_scroll = false): Promise<any> {
|
export function navigate(target: Target, id: number, noscroll = false): Promise<any> {
|
||||||
if (id) {
|
if (id) {
|
||||||
// popstate or initial navigation
|
// popstate or initial navigation
|
||||||
cid = id;
|
cid = id;
|
||||||
} else {
|
} else {
|
||||||
const current_scroll = scroll_state()
|
const current_scroll = scroll_state();
|
||||||
|
|
||||||
// clicked on a link. preserve scroll state
|
// clicked on a link. preserve scroll state
|
||||||
scroll_history[cid] = current_scroll;
|
scroll_history[cid] = current_scroll;
|
||||||
|
|
||||||
id = cid = ++uid;
|
id = cid = ++uid;
|
||||||
scroll_history[cid] = has_scroll ? current_scroll : { x: 0, y: 0 };
|
scroll_history[cid] = noscroll ? current_scroll : { x: 0, y: 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
cid = id;
|
cid = id;
|
||||||
|
|||||||
@@ -102,9 +102,9 @@ function handle_click(event: MouseEvent) {
|
|||||||
if (url.pathname === location.pathname && url.search === location.search) return;
|
if (url.pathname === location.pathname && url.search === location.search) return;
|
||||||
|
|
||||||
const target = select_route(url);
|
const target = select_route(url);
|
||||||
const has_scroll = a.hasAttribute('sapper-noscroll')
|
|
||||||
if (target) {
|
if (target) {
|
||||||
navigate(target, null, has_scroll);
|
const noscroll = a.hasAttribute('sapper-noscroll')
|
||||||
|
navigate(target, null, noscroll);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
history.pushState({ id: cid }, '', url.href);
|
history.pushState({ id: cid }, '', url.href);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user