Member-only story
How to make Jetpack Compose navigation easier and testable
Navigating in Compose is easy
Navigating in Jetpack Compose is pretty simple as you may already know. You just declare a NavHost
with all your destinations and a NavHostController
that will remember the navigation state and will let you controll your navigation.
For example:
We’ve just created a navController
using rememberNavController()
so that navigation state can survive recompositions and we declared two destinations: "firstScreen”
and "secondScreen"
so we can easily navigate between them.
Now to navigte from FirstScreen to SecondScreen we just use something like this:
Simple, right? But it has some drawbacks…