by @alexstyl
✉️ Leave your feedback

← Back to Compose Navigation

NavHost

Component
in
Compose Navigation
. Since 2.6.0

Overview

Examples

Community Notes

Video

Provides in place in the Compose hierarchy for self contained navigation to occur.

Once this is called, any Composable within the given NavGraphBuilder can be navigated to from the provided navController.

The builder passed into this method is remembered. This means that for this NavHost, the contents of the builder cannot be changed.

Overloads

@Deprecated(
    message = "Deprecated in favor of NavHost that supports AnimatedContent",
    level = DeprecationLevel.HIDDEN
)
@Composable
public fun NavHost(
    navController: NavHostController,
    startDestination: String,
    modifier: Modifier = Modifier,
    route: String? = null,
    builder: NavGraphBuilder.() -> Unit
)

Parameters

NameDescription
navControllerthe navController for this host
startDestinationthe route for the start destination
modifierThe modifier to be applied to the layout.
routethe route for the graph
builderthe builder used to construct the grap

@Composable
public fun NavHost(
    navController: NavHostController,
    startDestination: String,
    modifier: Modifier = Modifier,
    contentAlignment: Alignment = Alignment.Center,
    route: String? = null,
    enterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition) =
        { fadeIn(animationSpec = tween(700)) },
    exitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition) =
        { fadeOut(animationSpec = tween(700)) },
    popEnterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition) =
        enterTransition,
    popExitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition) =
        exitTransition,
    builder: NavGraphBuilder.() -> Unit
)

Parameters

NameDescription
navControllerthe navController for this host
startDestinationthe route for the start destination
modifierThe modifier to be applied to the layout.
contentAlignmentThe Alignment of the AnimatedContent
routethe route for the graph
enterTransitioncallback to define enter transitions for destination in this host
exitTransitioncallback to define exit transitions for destination in this host
popEnterTransitioncallback to define popEnter transitions for destination in this host
popExitTransitioncallback to define popExit transitions for destination in this host
builderthe builder used to construct the grap

@Deprecated(
    message = "Deprecated in favor of NavHost that supports AnimatedContent",
    level = DeprecationLevel.HIDDEN
)
@Composable
public fun NavHost(
    navController: NavHostController,
    graph: NavGraph,
    modifier: Modifier = Modifier
)

Parameters

NameDescription
navControllerthe navController for this host
graphthe graph for this host
modifierThe modifier to be applied to the layout

@SuppressLint("StateFlowValueCalledInComposition")
@Composable
public fun NavHost(
    navController: NavHostController,
    graph: NavGraph,
    modifier: Modifier = Modifier,
    contentAlignment: Alignment = Alignment.Center,
    enterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition) =
        { fadeIn(animationSpec = tween(700)) },
    exitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition) =
        { fadeOut(animationSpec = tween(700)) },
    popEnterTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> EnterTransition) =
        enterTransition,
    popExitTransition: (AnimatedContentTransitionScope<NavBackStackEntry>.() -> ExitTransition) =
        exitTransition,
)

Parameters

NameDescription
navControllerthe navController for this host
graphthe graph for this host
modifierThe modifier to be applied to the layout.
contentAlignmentThe Alignment of the AnimatedContent
enterTransitioncallback to define enter transitions for destination in this host
exitTransitioncallback to define exit transitions for destination in this host
popEnterTransitioncallback to define popEnter transitions for destination in this host
popExitTransitioncallback to define popExit transitions for destination in this hos
Previous ComponentLocalOwnersProvider