It may be not exactly what you're searching for, but I think it worth mentioning that can make use of the beforeNavigate
callback provided by $app/navigation
.
then, you can save the nav history in a store to use it across your application in order to manage some special cases.
/routes/__layout.svelte
<script>
$: console.log($previousPage, $nextPage);
import { beforeNavigate } from "$app/navigation";
beforeNavigate(({ from, to }) => {
$history = [to.pathname, ...$history];
});
</script>
{#if $history}
<ul>
{#each $history as url}
<li>{url}</li>
{/each}
</ul>
{/if history}
side note: from
& to
are URL Objects from the Web API:
https://developer.mozilla.org/en-US/docs/Web/API/URL
/routes/stores.svelte
import { writable } from 'svelte/store';
export const history = writable(['/']);
Here's a demo based on the SvelteKit Demo app:
https://stackblitz.com/edit/sveltejs-kit-template-default-wivfds?file=src%2Froutes%2Fstores.js&terminal=dev
reflength
variable come from? – Clance