I'm using Jetpack Compose navigation with type-safe routes. I have these screens:
sealed class NavRoute {
@Serializable
object Home : NavRoute()
@Serializable
object Login: NavRoute()
@Serializable
data class OrderDetail(val orderId: Int) : NavRoute()
}
Is there any way to cast navDestination to my TypeSafe NavRoute
class?
DisposableEffect(navController) {
val listener = NavController.OnDestinationChangedListener { _, navDestination, _ ->
Log.d("ScreenName", "Destination changed to ${navDestination.route}")
}
navController.addOnDestinationChangedListener(listener)
onDispose {
navController.removeOnDestinationChangedListener(listener)
}
}