Documentation Index
Fetch the complete documentation index at: https://mintlify.com/danielitoCode/compose_svelted/llms.txt
Use this file to discover all available pages before exploring further.
NavHost is the rendering surface of the Compose Svelted navigation system. It subscribes to a NavController’s backstack store, resolves the top entry against its list of registered routes, and displays the matching Svelte component inside an AnimatedContent wrapper. When the backstack changes — because navigate() or popBackStack() was called — the transition plays and the new screen appears.
NavHost owns no navigation logic of its own. All state lives in the controller you pass to it. This separation means you can create the controller at any point in the component tree, pass it down as a prop or through Svelte context, and mount NavHost wherever makes sense in your layout.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
navController | NavController | required | The controller whose backstack this host renders. |
routes | Array<{ route: { path: string }, component: any }> | required | Route-to-component mappings. Build this array with composable(). |
transition | ContentTransition | fade(320) | The animated transition played between screen changes. |
modifier | Modifier | Modifier.empty() | Applied to the outer container div of the host. |
composable(route, factory)
composable is a small helper that binds a route object to a component. The factory argument is a zero-argument function that returns the component class — the lazy-function form means you can use dynamic imports in a future version without changing the call site. For static imports the factory is simply () => MyScreen.
composable() calls to the routes prop of NavHost. The order of entries in the array does not matter; NavHost matches by route.path, not by position.
Props received by every screen
Each component rendered byNavHost automatically receives two props regardless of whether it declares them:
| Prop | Type | Description |
|---|---|---|
navController | NavController | The same controller instance passed to NavHost. Use it to call navigate() or popBackStack(). |
navBackStackEntry | NavBackStackEntry | The current { route, args } entry. Read args to access any payload passed during navigation. |
export let in the screen’s <script> block. You are not required to declare both.
Transitions
NavHost delegates animation to AnimatedContent internally. The transition prop accepts a ContentTransition value — a descriptor that AnimatedContent interprets when the targetState (the current route path) changes.
Three built-in transitions are available out of the box:
transition prop of NavHost:
Complete working example
The following files form a minimal but fully functional navigation flow: a login screen, a home screen, and a details screen with a typed argument.Route definitions
routes.ts
Navigation wrapper
MainNavigationWrapper.svelte
Login screen
LoginScreen.svelte
Home screen
HomeScreen.svelte
Details screen
DetailsScreen.svelte
Internal architecture notes
NavHost renders its active component inside AnimatedContent. The targetState passed to AnimatedContent is the route string of the current top backstack entry. Any time that string changes, AnimatedContent plays the configured ContentTransition and swaps the rendered component.
The container div wrapping AnimatedContent always has width: 100%; height: 100%; position: relative applied, with the modifier styles appended on top. Pass Modifier.fillMaxSize() from the parent to let the host expand to fill its allocated space.
Core V2 navigation is stable and closed for new features. Core V3 will introduce nested navigation graphs and directional transitions (e.g. distinguishing a forward slide from a back-pop slide). Upgrade instructions will be published alongside the V3 release.