I'm currently working on conditional navigation wh...
# compose
j
I'm currently working on conditional navigation where if the user is not logged in, the app navigates to the authentication screen. Currently, I place this conditional navigation logic in a
launchedEffect
of my main screen, but the app then momentarily shows the main screen before navigating to the auth screen if no user is logged in. I would like to remove the delay in navigating to the auth screen. I'm not entirely sure if using
launchedEffect
in this case is best practice too.
So something like this:
Copy code
@Composable
fun HomeScreen() {
     LaunchedEffect(isLoggedIn) { 
         if (!isLoggedIn) {
             navigateToAuthScreen()
         }
     }
}
w
You could do it before setting content and then use start destination as a variable
j
I'm not sure if I'm implementing your suggestions correctly. At the moment, I'd prefer to have my navigation logic and navigation graph in the same file, but now I'm extracting part of it into my MainActivity. Also, I would like my start destination to always be the home screen and not variable per this: https://developer.android.com/guide/navigation/navigation-principles#fixed_start_destination