Building a navigation graph
In Jetpack Compose, navigation is created using a NavHost
composable. This hosts NavGraph
, which defines your composable destinations; these are defined by routes. Navigating to and from these routes is done using NavHostController
, which is passed into NavHost
as its parameter name, navController
. The builder
parameter of NavHost (builder: NavGraphBuilder.() -> Unit)
creates NavGraph
. Look at the following example:
@Serializable
data object Home
@Serializable
data object Detail
@Composable
fun NavigationApp() {
val navController = rememberNavController()
NavHost(
navController = navController,
startDestination = Home,
builder = (
{
...