This example walks through building a complete three-screen application with Compose Svelted’s navigation system. Starting from a Login screen, the user is taken to a Home screen where they can navigate forward to a Details screen that receives typed arguments — and then pop back through the stack. Every transition is handled byDocumentation 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 and rememberNavController, mirroring the Jetpack Compose Navigation API.
Define routes
Routes are plain TypeScript objects with a Every
path string. Keeping them in a shared routes.ts module makes imports consistent across all screens and avoids magic strings.composable() call in NavHost references one of these objects, so renaming a route is a single-file change.Create the screens
Each screen is a plain Svelte component. Compose Svelted automatically injects two props into every routed component:HomeScreen.svelteThe Home screen demonstrates forward navigation with arguments. The object DetailsScreen.svelte
navController— the sameNavControllerinstance created in the host; use it tonavigate()orpopBackStack().navBackStackEntry— the back-stack entry for the current destination; its.argsproperty holds any arguments passed during navigation.
{ id: 42 } is passed as the second argument to navigate() and becomes available via navBackStackEntry.args on the Details screen.navBackStackEntry.args is destructured at the top of the script block. The nullish coalescing ?? {} guard keeps TypeScript happy when the entry is not yet hydrated.Wire NavHost
MainNavigationWrapper.svelte owns the NavController and declares the full route graph. rememberNavController() accepts the initial route path as its argument — here Home.path so the app opens directly on the home screen. Each composable() call maps a route object to a lazy screen factory () => ScreenComponent.NavHost accepts an optional transition prop. Import the transition helper and pass it directly:transition entirely for an instant cut between screens.Mount in App.svelte
Wrap the entire application in With
ComposeTheme and AppRoot. ComposeTheme provides the active colour scheme (light, dark, or automatic system detection) to every component in the tree. AppRoot sets up the root layout constraints.mode="system", ComposeTheme reads prefers-color-scheme from the browser and switches palettes automatically. Change to "light" or "dark" to pin the theme.ProfesionalLoginWithAnimation.svelte in the playground shows how to combine this navigation setup with AnimatedVisibility to animate the login card appearing on mount. The card is wrapped in AnimatedVisibility with enter={fadeIn()} and exit={fadeOut()}, and a boolean state variable is set to true so the enter animation fires immediately on mount:scaleIn is also available as an enter animation and pairs well with fadeOut for a card-dismiss effect.