store uri in nav history

This commit is contained in:
Nikita Galaiko 2023-03-28 08:00:04 +02:00
parent 2c76b6185b
commit 5e4b957fd9

View File

@ -2,15 +2,17 @@
import { afterNavigate, goto } from '$app/navigation';
import { page } from '$app/stores';
const getUri = (url: URL) => url.pathname + url.search + url.hash;
let position = 0;
const history = [$page.url.pathname];
const history = [getUri($page.url)];
$: canGoBack = history.length > 1 && position > 0;
$: canGoForward = history.length > 1 && position < history.length - 1;
afterNavigate((nav) => {
if (nav.to === null) return;
const to = nav.to.url.pathname;
const to = getUri(nav.to.url);
if (to === history[position]) {
return;
} else if (to === history[position + 1]) {