A question regarding nested routes
# compose
v
A question regarding nested routes
Hello, I am reading about nested routes trying to understand their advantages and looking at the examples online. I have found this example on Github where the person has created a separate nested navigation graph and put all the pertinent routes inside, creating a flow for the users that are logged in: https://github.com/KenAli77/InFit/blob/master/app/src/main/java/ken/projects/infit/ui/navigation/MainNavGraph.kt However that poses the following 2 questions: 1. I like the idea of creating separate navigation flows (unauthed/ authed etc. ) and grouping routes together like that. However, doesn't it cause all the routes to be piled on under a single navigation graph that way, making it more difficult to reason about them? What are the benefits of such flows? 2. Furthermore, since all the routes share the same navgraph flow , doesn't it become very difficult to pass in parameters (e.g. passing down
onNavigateToHomeScreen= { navController.navigate(Home) }
) into individual screens through the navigation graph? Is there a way to avoid this problem and perhaps still be able to modularize the routes while having them inside a nested graph?
For example:
Copy code
@Composable
fun AppNavHost(
    navController: NavHostController,
    startDestination: Any
) {

    NavHost(navController = navController, startDestination = startDestination) {
        mainScreenGraph(onNavigateToScanScreen = { navController.navigate(ScreenA) })
        featureAScreenGraph()
        featureBScreenGraph()
        loginScreenGraph()
    }

}
a) If I were to pass down all kinds of
onNavigate()
functions from
AppNavHost
wouldn't it make this file bloated? Also, the inner feature nested graphs would need to instantiate all the viewmodels that all the Screens inside them require. I am not sure if that is a good thing?
👍 1