Navigate between composables¶
Use a EunGabiController¶
The EunGabiController
provides ways to navigate between composables. See the Create Navigation Controller section for instructions on instantiating the EunGabiController
.
val controller = rememberEunGabiController()
Navigate to a Composable¶
To navigate to a composable, you should call the EunGabiController.navigate
. navigate()
takes a route defined in the EunGabiGraphBuilder
of EunGabiNavHost
. See Create a Navigation Host Composable section for instructions on creating a EunGabiGraph
.
controller.navigate("ScreenA")
By calling this, you can navigate to the ScreenA
route.
Pop up to a destination¶
To remove destinations from the back stack when navigating from one destination to another, add a popUpTo()
argument to the associated navigate()
function call.
You can include an argument for the inclusive
option with a value of true
to also pop up a destination you have specified in popUpTo()
.
Let's assume we have screens A, B, C, and D in the back stack.
The following snippets demonstrate how to pop up to the ScreenA
when navigating up from ScreenD
:
controller.navigate("ScreenD") {
popUpTo("ScreenB") {
inclusive = true
}
}
Tip
If the inclusive
option were false
, the result would be a pop-up to ScreenB
.
Navigate back¶
You can navigate to the previous screen by calling NavController.navigateUp
. It returns a Boolean
value indicating the success of the back navigation.
controller.navigateUp()