Level 7
Modern Navigation
Navigation Compose
Single Activity, multiple Composable destinations. Defined via a Navigation Graph.
📚 Explanation
Navigation Compose uses a type-safe, declarative API. Routes are defined as strings with optional parameters. The `NavHost` manages the navigation graph and back stack automatically.
Note: Code execution is not available for Android/Kotlin in the browser. Use Android Studio to run and test the app.
import androidx.navigation.compose.NavHostimport androidx.navigation.compose.composableimport androidx.navigation.compose.rememberNavController@Composablefun AppNavigation() {val navController = rememberNavController()NavHost(navController = navController, startDestination = "home") {composable("home") {HomeScreen(onNavigateToProfile = { userId ->navController.navigate("profile/$userId")})}// Handling Argumentscomposable("profile/{userId}") { backStackEntry ->val userId = backStackEntry.arguments?.getString("userId")ProfileScreen(userId)}}}