I am having an issue with scoping my ViewModel to ...
# compose
k
I am having an issue with scoping my ViewModel to nested graph, the ViewModel is getting initilalized again, but the ViewModel scoped with screen composable survives.
Copy code
NavHost(
    navController = navHostController,
    startDestination = Screen.FirstScreen.route
) {
    composable(route = Screen.FirstScreen.route) {
        FirstScreen(text = Screen.FirstScreen.route)
    }

    navigation(startDestination = Screen.SecondScreen.route, route = Screen.SecondScreenGraph.route) {
        composable(route = Screen.SecondScreen.route) {
            val graphEntry = remember {
                navHostController.getBackStackEntry(Screen.SecondScreenGraph.route)
            }

            val viewmodel = viewModel<GraphViewModel>(graphEntry)
            SecondScreen(text = Screen.SecondScreen.route)
        }
    }
}
This is my graph,
GraphViewModel
is initialized again each time, but the viewModel inside
SecondScreen
survives.