This function sets up the navigation connections and saves all the correct initializations of ViewModels for each page.
LaunchedEffect(lifecycleOwner) {
viewModel.navigationEvent
.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
.collect { event -> // Catch event triggers
when (event) {
is NavigationEvent.NavigateToHome -> // select trigger
navController.navigate("home") // send to new page
is NavigationEvent.NavigateBack ->
navController.popBackStack()
}
}
}
NavHost(navController = navController, startDestination = "home") { // set start page
composable("home") { HomeView(viewModel) } // define local reference and init page
}