'Implementing back navigation in Jetpack Compose

I've got a top bar with IconButton for handling back navigation when clicked.

Function passed as callback's implemented like this:

private fun navigateBack(navController: NavController) {
    val route = navController.previousBackStackEntry?.destination?.route ?: ""
    navController.navigate(route)
}

Unfortunately, it's not working the same as the default android bottom navigation shown in the picture

enter image description here

Is there a way to implement the same back navigation as bottom system navigation has?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source