I'm getting an error when trying to navigate to an...
# compose
I'm getting an error when trying to navigate to another graph with arguments. I'm not sure what I'm doing wrong here This is the error I'm getting:
java.lang.IllegalArgumentException: Wrong argument type for 'userId' in argument bundle. integer expected.
Copy code
object ProfileDestination : GenericDestination {
    override val route = "profile_route/{userId}"
    override val startDestination = "profile_destination/{userId}"
    const val argsUserId = "userId"
    operator fun invoke(id: Int) = "profile_route/$id"

fun NavGraphBuilder.profileGraph() {
    navigation(startDestination = ProfileDestination.startDestination, ProfileDestination.route) {
            route = ProfileDestination.startDestination,
            arguments = listOf(navArgument(ProfileDestination.argsUserId) {
                type = NavType.StringType
        ) { Profile() }
Copy code
Changing the NavType to StringType solves the issue for some reason. I'm not sure why it doesn't accept integers
It looks like you are navigating to the navigation graph (the
element), which doesn't have any
defined, so you're just getting the default, which is strings. Generally, you'll want to navigate directly to the destination rather than to a navigation graph:
Copy code
operator fun invoke(id: Int) = "profile_destination/$id"
tbh, I don't know why you have the navigation graph there at all. your whole
could just be a single
destination, skipping the intermediate layer entirely?
I'm splitting features of the app to have their individual navigation graph. Basically the same way that it was recommended in the fragment navigation when having a multi-module app. Is this not the case with navigation compose anymore?
What are the uses of the nested graphs, I'm guessing it can be used to define different starting destinations based on the business logic. Other than that should I just navigate to composables directly within the same graph?
Having separate navigation graphs is great, do that - it'll affect your generated back stack when you deep link to a destination and give you a shared scope for all destinations within that graph. There's just no reason to navigate to the graph itself instead of directly to the destination you want to go to
Thanks! That was really helpful