In jetpack navigation compose, how do I do the fol...
# compose
a
In jetpack navigation compose, how do I do the following in a typesafe manner (using classes, not strings … this is from
JetSnackNavController
)
Copy code
fun navigateToBottomBarRoute(route: String) {
        if (route != navController.currentDestination?.route)
The goal is to prevent the user from pressing the same top level Route over and over, which based on the typical Bottom Nav code I see, causes the `compose`<> block to rerun, viewmodels to be recreated, etc.
e
Hello! In my app, I'm using the
hasRoute()
API, which is very useful for comparing the typesafe with the BackStackEntry. Something like:
Copy code
navHostController.currentBackStackEntry?.destination?.hasRoute(route::class) == true
https://github.com/igorescodro/alkaa/blob/a9023a1006156c298eaedaebb13e333356c3cc8b[…]/commonMain/kotlin/com/escodro/navigation/compose/Navigation.kt
a
Ah thanks very much! I was looking at
hasRoute
, but could not figure out how I would use it with multiple routes using the same class (different default args). I probably should not do that