When deep linking via NavHost, is your startDestin...
# compose-android
j
When deep linking via NavHost, is your startDestination temporary ignored and the NavHost correctly shows the deep linked route immediately? My app’s start destination has initial start up functionality (routes to login if not authenticated) that I would like to avoid during deep linking.
s
The start destination is indeed not shown at all, nor is it in the backstack at all in the deep link case actually. You can't just have the "log out" logic in your start destination, that has to be done either in each destination through some wrapper, or globally outside of which destination you are in
Note that you can not go around that. It works this way so that if you're deep linked from some other app, if the user goes back they end up back in the app they came from, instead of staying in your app. And it's also why
navigateUp()
does things differently in those specific scenarios where there is nothing else in the backstack so it recreates a new one depending on where you navigated up from.
j
That’s awesome about the start destination not being shown. Which is what I want I definitely don’t want to get around it.
👍 1
Looks like I misunderstood this

video

. I thought Ian was suggesting that only your start destination should have logic to route to your Login route. Major oops.
s
Yeap, what we do if it helps, is that we have this check above the NavHost completely https://github.com/HedvigInsurance/android/blob/415970adbf119fc86e8659f912b400cb2c[…]/app/app/src/main/kotlin/com/hedvig/android/app/ui/HedvigApp.kt And it's defined here https://github.com/HedvigInsurance/android/blob/415970adbf119fc86e8659f912b400cb2c[…]/app/app/src/main/kotlin/com/hedvig/android/app/ui/HedvigApp.kt We have 2 sources of truth of if you're logged in or not, some auth status and if you're in "demo mode". And when any of the two update, we also do a check for our current nav destination, and if we are not in the "logged out" navgraph then we navigate there.
j
This is fantastic! Much much better than having it in every destination.
🌟 1