how would one override back behavior for specific ...
# compose
p
how would one override back behavior for specific navigation destination? For example, if I have destination A,B,C,D, I would like for D to always pop back to A, given that you can navigate to D from A,B,C.
I guess I should do it like this
Copy code
NavHost(...) {
    composable(...) {
        BackHandler { /* navigate to A */}
        D()
    }
}
👍 1
i
No, that won't do what you want, particularly when you add animations (i.e., with Accompanist Navigation Animation) as
navigate
will go in a forward direction rather than run the pop animations. You should add
popUpTo("a") { inclusive = true }
to each time you navigate to D - then the back stack will already be correct when you hit the system back button
🍺 1