Let's suppose we have a bottom tab navigation and we want to switch between the tabs and keep their history. Guia allows that behavior using a NavHost:
First we declare our different keys for each stack (or tab):
As you can see we can have different nav container params based on our stack key.
Switch navigators
To switch which navigator is currently active we can use setActive:
navHost.setActive(FeedStackKey)
Navigating using NavHost
We can also directly navigate using the NavHost using currentNavigator or navigator(key) functions:
navHost.currentNavigator?.push(SomeKey())// Although we aren't on HomeStackKey, we can still navigate in that contextnavHost.navigator(HomeStackKey).push(SomeKey())
Getting NavHost Instance
// Get the local nav host, returns nullable NavHostval navHost =localNavHost()// Use when you are 100% sure there's a nav host in the tree hierarchyval navHost =requireLocalNavHost()