In the new Navigation architecture component, how to implement conditional navigation?
Currently I have a single activity with LoginFragment and HomeFragment. Based on a
This is how I deal with conditional navigation :
Create a global action for LoginFragment
Perform conditional navigation inside onViewCreated
:
// HomeFragment.kt
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
if(!appAuth.isAuthenticated()) {
view.findNavController().navigate(R.id.action_global_loginFragment)
}
}