{"id":45749,"date":"2021-11-22T20:13:28","date_gmt":"2021-11-22T11:13:28","guid":{"rendered":"https:\/\/www.charlezz.com\/?p=45749"},"modified":"2021-11-22T20:13:29","modified_gmt":"2021-11-22T11:13:29","slug":"jetpack-compose-navigation-%ec%99%84%ec%84%b1%eb%90%9c-navhost-%ec%b6%94%ec%b6%9c%ed%95%98%ea%b8%b0","status":"publish","type":"post","link":"https:\/\/charlezz.com\/?p=45749","title":{"rendered":"Jetpack Compose Navigation &#8211; \uc644\uc131\ub41c NavHost \ucd94\ucd9c\ud558\uae30"},"content":{"rendered":"\n<p>\uc774\uc81c NavHost\ub97c \uc644\uc131\ud588\ub2e4. RallyApp \ucef4\ud3ec\uc800\ube14\ub85c\ubd80\ud130 NavHost\ub97c \ucd94\ucd9c\ud558\uc5ec \uc790\uc2e0\ub9cc\uc758 \ud568\uc218\ub85c \ub9cc\ub4e4 \uc218 \uc788\uace0, \uc774\ub97c RallyNavHost\ub77c\uace0 \ubd80\ub974\uc790. \uc774\ub294 navController\uc640 \uc9c1\uc811 \uc791\uc5c5\ud574\uc57c \ud558\ub294 \uc720\uc77c\ud55c \ucef4\ud3ec\uc800\ube14\uc774 \ub420\uac83\uc774\ub2e4. RallyNavHost \ub0b4\uc5d0\uc11c navController\ub97c \uc0dd\uc131\ud558\uc9c0 \uc54a\uc74c\uc73c\ub85c\uc368 RallyApp \ub0b4\uc5d0\uc11c \uc0c1\uc704 \uad6c\uc870 \uc77c\ubd80\uc778 \ud0ed \uc120\ud0dd\uc744 \ub9cc\ub4dc\ub294 \ub370 \uacc4\uc18d \uc0ac\uc6a9\ud560 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Composable<br>fun RallyNavHost(<br>&nbsp; &nbsp; navController: NavHostController,<br>&nbsp; &nbsp; modifier: Modifier = Modifier<br>) {<br>&nbsp; &nbsp; NavHost(<br>&nbsp; &nbsp; &nbsp; &nbsp; navController = navController,<br>&nbsp; &nbsp; &nbsp; &nbsp; startDestination = Overview.name,<br>&nbsp; &nbsp; &nbsp; &nbsp; modifier = modifier<br>&nbsp; &nbsp; ) {<br>&nbsp; &nbsp; &nbsp; &nbsp; composable(Overview.name) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OverviewBody(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onClickSeeAllAccounts = { navController.navigate(Accounts.name) },<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onClickSeeAllBills = { navController.navigate(Bills.name) },<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; onAccountClick = { name -&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; navController.navigate(\"${Accounts.name}\/$name\")<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; composable(Accounts.name) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AccountsBody(accounts = UserData.accounts) { name -&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; navController.navigate(\"Accounts\/${name}\")<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; composable(Bills.name) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BillsBody(bills = UserData.bills)<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; val accountsName = Accounts.name<br>&nbsp; &nbsp; &nbsp; &nbsp; composable(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \"$accountsName\/{name}\",<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; arguments = listOf(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; navArgument(\"name\") {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; type = NavType.StringType<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; deepLinks = listOf(navDeepLink {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uriPattern = \"example:\/\/rally\/$accountsName\/{name}\"<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }),<br>&nbsp; &nbsp; &nbsp; &nbsp; ) { entry -&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; val accountName = entry.arguments?.getString(\"name\")<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; val account = UserData.getAccount(accountName)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SingleAccountBody(account = account)<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<p>\ub610\ud55c \uc6d0\ub798 NavHost\ub97c \ud638\ucd9c \ud558\ub358 \uacf3\uc5d0\uc11c RallyNavHost(navController)\ub85c \uad50\uccb4\ud558\uc5ec \uc758\ub3c4\ud55c \ub300\ub85c \uc791\ub3d9\ub418\ub3c4\ub85d \ud558\uc790.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>fun RallyApp() {<br>&nbsp; &nbsp; RallyTheme {<br>&nbsp; &nbsp; ...<br>&nbsp; &nbsp; &nbsp; &nbsp; Scaffold(<br>&nbsp; &nbsp; &nbsp; &nbsp; ...<br>&nbsp; &nbsp; &nbsp; &nbsp; ) { innerPadding -&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RallyNavHost(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; navController = navController,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; modifier = Modifier.padding(innerPadding)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; )<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp;}<br>}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\uc774\uc81c NavHost\ub97c \uc644\uc131\ud588\ub2e4. RallyApp \ucef4\ud3ec\uc800\ube14\ub85c\ubd80\ud130 NavHost\ub97c \ucd94\ucd9c\ud558\uc5ec \uc790\uc2e0\ub9cc\uc758 \ud568\uc218\ub85c \ub9cc\ub4e4 \uc218 \uc788\uace0, \uc774\ub97c RallyNavHost\ub77c\uace0 \ubd80\ub974\uc790. \uc774\ub294 navController\uc640 \uc9c1\uc811 \uc791\uc5c5\ud574\uc57c \ud558\ub294 \uc720\uc77c\ud55c \ucef4\ud3ec\uc800\ube14\uc774 \ub420\uac83\uc774\ub2e4. RallyNavHost \ub0b4\uc5d0\uc11c navController\ub97c \uc0dd\uc131\ud558\uc9c0 \uc54a\uc74c\uc73c\ub85c\uc368 RallyApp \ub0b4\uc5d0\uc11c \uc0c1\uc704 \uad6c\uc870 \uc77c\ubd80\uc778 \ud0ed \uc120\ud0dd\uc744 \ub9cc\ub4dc\ub294 \ub370 \uacc4\uc18d \uc0ac\uc6a9\ud560 \uc218 \uc788\ub2e4. \ub610\ud55c \uc6d0\ub798 NavHost\ub97c \ud638\ucd9c \ud558\ub358 \uacf3\uc5d0\uc11c RallyNavHost(navController)\ub85c \uad50\uccb4\ud558\uc5ec \uc758\ub3c4\ud55c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[38],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/45749"}],"collection":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=45749"}],"version-history":[{"count":1,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/45749\/revisions"}],"predecessor-version":[{"id":45750,"href":"https:\/\/charlezz.com\/index.php?rest_route=\/wp\/v2\/posts\/45749\/revisions\/45750"}],"wp:attachment":[{"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=45749"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=45749"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/charlezz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=45749"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}