Using the new Compose Type-Safe Navigation. How can you check if the currentBackstackEntry is a specific route?
val backStackEntry by navController.currentBackStackEntryAsState()
LaunchedEffect(backStackEntry) {
val route: Route = backStackEntry?.toRoute() // Always returns null, even when backStackEntry route is not null
}
I currently am using a workaround using the qualified name:
val route = backStackEntry?.destination?.route == Screen.Profile::class.qualifiedName
Though I would prefer a better method.
I personally would expect that if I do toRoute() I could do a check like
route is Screen.Profile
but since toRoute always returns null this check will always fail
The way I have build my routes:
sealed interface Screen {
sealed interface Auth: Screen {
@Serializable
data object Login : Auth
@Serializable
data object Register: Auth
}
@Serializable
data object Profile: Screen
}