← Back to Compose Navigation
NavHost
Component
in
Compose Navigation
. Since 2.6.0Overview
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
NavHost
@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
Name | Description |
---|---|
navController | the navController for this host |
startDestination | the route for the start destination |
modifier | The modifier to be applied to the layout. |
route | the route for the graph |
builder | the builder used to construct the grap |
NavHost
@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
Name | Description |
---|---|
navController | the navController for this host |
startDestination | the route for the start destination |
modifier | The modifier to be applied to the layout. |
contentAlignment | The Alignment of the AnimatedContent |
route | the route for the graph |
enterTransition | callback to define enter transitions for destination in this host |
exitTransition | callback to define exit transitions for destination in this host |
popEnterTransition | callback to define popEnter transitions for destination in this host |
popExitTransition | callback to define popExit transitions for destination in this host |
builder | the builder used to construct the grap |
NavHost
@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
Name | Description |
---|---|
navController | the navController for this host |
graph | the graph for this host |
modifier | The modifier to be applied to the layout |
NavHost
@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
Name | Description |
---|---|
navController | the navController for this host |
graph | the graph for this host |
modifier | The modifier to be applied to the layout. |
contentAlignment | The Alignment of the AnimatedContent |
enterTransition | callback to define enter transitions for destination in this host |
exitTransition | callback to define exit transitions for destination in this host |
popEnterTransition | callback to define popEnter transitions for destination in this host |
popExitTransition | callback to define popExit transitions for destination in this hos |
Previous Component← LocalOwnersProvider