Software Development/Application Develop

Jetpack Compose - Navigation

huiyu 2024. 7. 27. 23:44
setContent {
    val navController = rememberNavController()

    NavHost(
        navController = navController,
        startDestination = "first"
    ){
        composable("first"){
            FirstScreen()
        }
        composable("second"){
            SecondScreen()
        }
        composable("third"){
        }
    }
}
@Composable
fun FirstScreen() {

}

@Composable
fun SecondScreen() {

}

@Composable
fun ThirdScreen() {

}

이동

navController.navigate("second")

뒤로가기

navController.naviagteUp() or navController.popBackStack()

 

third가 실행될때 값을 넘기기

아래와 같이 넘기면되는데,

navController.navigate("third/$value")

 

composable선언시. 이렇게 받아올 수 있다.

composable("third/{value}") { backStackEntry->
	ThirdScreen(
    	navController = navController,
        value = backStackEntry.arguments?.getString("value")?:"",
    )
}

 

 

 

 

728x90