question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Nested graphs without root destination

See original GitHub issue

Is it possible to create a NavGraph without a root destination like below?

NavHost(
    navController = navController,
    startDestination = "tab_home"
) {
    navigation(
        route = "tab_home",
        startDestination = "start",
    ) {
        composable("start") { /* */ }
        composable("next") { /* */ }
    }
    navigation(
        route = "tab_setting",
        startDestination = "setting"
    ) {
        composable("setting") { /* */ }
    }
}

I added navGraph option to all @Destination but the NavGaphs with Exception was generated.

object NavGraphs {
    val tabHome = NavGraph(/* */)
    val tabSettings = NavGraph(/* */)
    val root: NavGraph = throw RuntimeException("No found destinations for 'root' navigation graph")
}

Is there any solution?

I use version 1.1.5-beta.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
STAR-ZEROcommented, Jan 19, 2022

Thank you for dealing with it so quickly. 😃

1reaction
STAR-ZEROcommented, Jan 19, 2022

Thank you for helping.

I tried to create NavGraphs manually, but I didn’t know what to set for root’s startDestination.

object NavGraphs {

    val tabHome = NavGraph(
        // ...
    )

    val tabSettings = NavGraph(
        // ...
    )

    val root = NavGraph(
        route = "root",
        startDestination = /* ???? */,
        destinations = emptyList(),
        nestedNavGraphs = listOf(
            tabHome,
            tabSettings
        ),
    )
}

I tried setting tabHome.startDestination, but it throws IllegalArgumentException.

java.lang.IllegalArgumentException: navigation destination start_screen is not a direct child of this NavGraph
Read more comments on GitHub >

github_iconTop Results From Across the Web

Nested navigation graphs - Android Developers
A series of destinations can be grouped into a nested graph within a parent navigation graph called the root graph. Nested graphs are...
Read more >
Navigation: Nested graphs and include tag | Android Developers
Nested graphs have their own start destination and don't expose their child destinations separately.
Read more >
android - New navigation component from arch with nested ...
Camera is direct destination without any nested graph, Dashboard has it's own nested graph but it's added to same backstack camera fragment ...
Read more >
Using nested graph for a bottom bar destination recreates its ...
Let's say you have a bottom bar with three destinations (for instance A, B, C). There are attached to the same nav graph...
Read more >
Navigating between modules - MAD Skills - YouTube
In this episode, Murat will demonstrate how you can organize the Navigation graph by using nested graphs and using the include tag to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found