What's the issue with passing a navigator into a c...
# compose
c
What's the issue with passing a navigator into a composable or viewmodel?
p
In a Composable is not too bad, perhaps creates an extra dependency, one more to mock in tests, in the case of viewmodels might leak if not handled careful
j
A good part of an article I wrote a while ago talks about this: https://medium.com/google-developer-experts/navigating-in-jetpack-compose-78c78d365c6a
s
Right, but this article doesn't mention anything regarding passing it to the ViewModel. Aside from making sure you want to keep your navigation logic in one place and not passing it down to every composable, what is the situation like when you want to pass it to the ViewModel in order to avoid having to make a trampoline move, of the VM telling the composable to navigate, which itself calls the NavController, and then have the composable report back to the ViewModel that yes this navigation happened. As opposed to skipping the middle man and having the ViewModel tell the NavController directly to navigate somewhere.