Tanjim ahmed
Tanjim ahmed

Reputation: 599

How to change Jetpack compose navigation component backstack behaviour?

I implemented the login, sign-up with jetpack compose on an app. I redirected the logged-in users to the main screen and keep the new user on to the login screen. But the problem is when I redirect the user from the login screen to the main screen and the user press the back button the login screen appears. Now I know it's a normal behavior of the navigation component but I need to change it. How can I do that?

Used this line for navigating to the main screen from the login screen

navController().navigate("main_screen")

Upvotes: 1

Views: 1430

Answers (1)

Phil Dukhov
Phil Dukhov

Reputation: 88467

You can remove last item from the back stack before navigating to the main screen using popBackStack:

navController.popBackStack()
navController.navigate("main_screen")

Upvotes: 2

Related Questions