Basic Svelte
Introduction
Bindings
Advanced Svelte
Advanced reactivity
Motion
Advanced bindings
Advanced transitions
Context API
Special elements
<script module>
Next steps
Basic SvelteKit
Introduction
Routing
Loading data
Headers and cookies
Shared modules
API routes
Stores
Errors and redirects
Advanced SvelteKit
Page options
Link options
Advanced routing
Advanced loading
Environment variables
Conclusion
The navigating
store represents the current navigation. When a navigation starts — because of a link click, or a back/forward navigation, or a programmatic goto
— the value of navigating
will become an object with the following properties:
from
andto
— objects withparams
,route
andurl
propertiestype
— the type of navigation, e.g.link
,popstate
orgoto
For complete type information visit the
Navigation
documentation.
It can be used to show a loading indicator for long-running navigations. In this exercise, src/routes/+page.server.js
and src/routes/about/+page.server.js
both have an artificial delay. Inside src/routes/+layout.svelte
, import the navigating
store and add a message to the nav bar:
src/routes/+layout
<script>
import { page, navigating } from '$app/stores';
let { children } = $props();
</script>
<nav>
<a href="/" aria-current={$page.url.pathname === '/'}>
home
</a>
<a href="/about" aria-current={$page.url.pathname === '/about'}>
about
</a>
{#if $navigating}
navigating to {$navigating.to.url.pathname}
{/if}
</nav>
{@render children()}
1
2
3
<h1>home</h1>
<p>this is the home page.</p>