0xf1f1
03/12/2024, 9:05 AMjava.lang.IllegalArgumentException: Destination Destination(0x4270f667) route=/login cannot have the same route as graph ComposeNavGraph(0x4270f667) route=/login startDestination=0x0
0xf1f1
03/12/2024, 9:06 AMNavHost(
navController = navController,
startDestination = "/login",
) {
composable(route = "/login") {
LoginScreen(loginViewModel::onEvent, loginViewModel.state)
}
navigation(
startDestination = "/suryer",
route = "/suryer"
) {
composable(route = "/suryer") {
HomeScreen()
}
}
}
Bharat Kumar
03/12/2024, 9:14 AMBharat Kumar
03/12/2024, 9:17 AMjava.lang.IllegalArgumentException: Destination Destination(0x17f98b58) route=/suryer cannot have the same route as graph ComposeNavGraph(0x17f98b58) route=/suryer startDestination=0x0
Bharat Kumar
03/12/2024, 9:17 AM0xf1f1
03/12/2024, 9:20 AMnavigation() fun
that is causing the issue. doesnt matter what I change it to, it gives me the same erorBharat Kumar
03/12/2024, 9:26 AMNavHost(
navController = rememberNavController(),
startDestination = "/login",
) {
composable(route = "/login") {
Box(modifier = Modifier.fillMaxSize())
}
navigation(
startDestination = "/suryer",
route = "/suryers"
) {
composable(route = "/suryers") {
Box {
}
}
}
}
try this once this works for meBharat Kumar
03/12/2024, 9:27 AM0xf1f1
03/12/2024, 9:28 AMimport androidx.navigation.compose.NavHost
import androidx.navigation.compose.navigation
Bharat Kumar
03/12/2024, 9:29 AMimport androidx.navigation.navigation
use this @0xf1f1Stylianos Gakis
03/12/2024, 9:44 AMandroidx.navigation.compose.navigation
is correct for what they’re trying to do.
I think you just need to not use the same route for a navgraph and then the same one for one of the destinations.
This is also a bit wrong since you mark the startDestination as the nav graph’s route, and not of the child route.
Do something like this instead and it should work
NavHost(
navController = navController,
startDestination = "/login",
) {
composable(route = "/login") {
LoginScreen(loginViewModel::onEvent, loginViewModel.state)
}
navigation(
route = "/suryer"
startDestination = "/suryerhome",
) {
composable(route = "/suryerhome") {
HomeScreen()
}
}
}
And then just rename appropriately.
Or just ditch the strings completely and use this to have an easier time overall with thisBharat Kumar
03/12/2024, 9:47 AMBharat Kumar
03/12/2024, 9:48 AMStylianos Gakis
03/12/2024, 10:13 AMya sorry copied the wrong oneYeap, an easy thing to miss. And it’s especially problematic when you do it in your code itself and then you got bugs which you have no idea about due to the string nature of this API. I am mostly suggesting the kiwi-navigation one because that’s exactly the same approach that the official navigation library is also working on right as we speak to provide first party support for type-safety in navigation. You can look at the work being done here https://issuetracker.google.com/issues/188693139 by looking at the commits there. So if you go with that, migrating to 1st party support should be completely effortless. Read comment #12 here or see this commit for proof
0xf1f1
03/12/2024, 10:15 AMNavHost(
navController = navController,
startDestination = "/login",
) {
composable(route = "/login") {
LoginScreen(loginViewModel::onEvent, loginViewModel.state)
}
navigation(
startDestination = "/suryer",
route = "suryer_route"
) {
composable(route = "/suryerhome") {
HomeScreen()
}
}
}
Stylianos Gakis
03/12/2024, 10:16 AMnavigation(
startDestination = "/suryer",
route = "suryer_route"
) {
composable(route = "/suryerhome") {
HomeScreen()
}
}
This is also wrong because the start destination is not pointing to any route in its children.Stylianos Gakis
03/12/2024, 10:18 AMroute
as the url of a website, every page you have has to be unique.
Then as far as navigation
and the root NavHost goes, it’s a bit more special where the route to that also has to be unique, but navigating to that one won’t show some UI from there, but it will then go to the route of the startDestination
and then show that instead.
I suggest reading the navigation docs to understand all this a bit better if you want to work more with this. Like this page for example https://developer.android.com/guide/navigation/design/nested-graphsStylianos Gakis
03/12/2024, 10:19 AMnavController.navigate("gameInProgress")
will in fact go to composable("match")
, since it’s the start destination of it.0xf1f1
03/12/2024, 7:09 PM0xf1f1
03/12/2024, 7:50 PMnavigation(route = "auth") { composable(route = "/auth/login") {} }
Stylianos Gakis
03/12/2024, 7:52 PM0xf1f1
03/13/2024, 9:49 AMjava.lang.IllegalArgumentException: navigation destination login is not a direct child of this NavGraph
@Composable
fun NavGraph(navController: NavHostController) {
NavHost(
navController = navController,
startDestination = NavRoute.Auth.Login.path
) {
auth(this)
}
}
private fun auth(
builder: NavGraphBuilder,
) {
builder.navigation(
startDestination = NavRoute.Auth.Login.path,
route = NavRoute.Auth.route
) {
composable(route = NavRoute.Auth.Login.path) {
LoginScreen()
}
}
}
0xf1f1
03/13/2024, 9:50 AMStylianos Gakis
03/13/2024, 9:52 AMNavHost
|
|-> NavRoute.Auth.route (nested nav graph)
|
|-> NavRoute.Auth.Login.path (composable)
You are trying to make NavRoute.Auth.Login.path (composable)
the start destination of NavHost, but that’s not possible since it’s not a child of it.
What you probably want here is for NavRoute.Auth.route
to be the start destination of NavHost, which will then in turn go to the start destination of NavRoute.Auth.route
which is NavRoute.Auth.Login.path
0xf1f1
03/13/2024, 9:56 AM