# NavHostKt

Added in 2.3.0

*** ** * ** ***


```
public final class NavHostKt
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavGraph` | `[createGraph](https://developer.android.com/reference/androidx/navigation/dynamicfeatures/NavHostKt#(androidx.navigation.NavHost).createGraph(kotlin.Int,kotlin.Int,kotlin.Function1))( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavHost receiver, @https://developer.android.com/reference/androidx/annotation/IdRes int id, @https://developer.android.com/reference/androidx/annotation/IdRes int startDestination, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/dynamicfeatures/DynamicNavGraphBuilder, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> builder )` **This method is deprecated.** Use routes to create your dynamic NavGraph instead |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavGraph` | `https://developer.android.com/reference/androidx/navigation/dynamicfeatures/NavHostKt#(androidx.navigation.NavHost).createGraph(kotlin.String,kotlin.String,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavHost receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html startDestination, https://developer.android.com/reference/java/lang/String.html route, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/dynamicfeatures/DynamicNavGraphBuilder, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> builder )` Construct a new `https://developer.android.com/reference/androidx/navigation/NavGraph` that supports dynamic navigation destinations |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavGraph` | `https://developer.android.com/reference/androidx/navigation/dynamicfeatures/NavHostKt#(androidx.navigation.NavHost).createGraph(kotlin.Any,kotlin.reflect.KClass,kotlin.collections.Map,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavHost receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html startDestination, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> route, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-type/index.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavType<@https://developer.android.com/reference/androidx/annotation/NonNull ?>> typeMap, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/dynamicfeatures/DynamicNavGraphBuilder, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> builder )` Construct a new `https://developer.android.com/reference/androidx/navigation/NavGraph` that supports dynamic navigation destinations |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavGraph` | `https://developer.android.com/reference/androidx/navigation/dynamicfeatures/NavHostKt#(androidx.navigation.NavHost).createGraph(kotlin.reflect.KClass,kotlin.reflect.KClass,kotlin.collections.Map,kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavHost receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> startDestination, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> route, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-type/index.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavType<@https://developer.android.com/reference/androidx/annotation/NonNull ?>> typeMap, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/dynamicfeatures/DynamicNavGraphBuilder, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> builder )` Construct a new `https://developer.android.com/reference/androidx/navigation/NavGraph` that supports dynamic navigation destinations |

## Public methods

### createGraph

Artifact: [androidx.navigation:navigation-dynamic-features-runtime](https://developer.android.com/jetpack/androidx/releases/navigation) [View Source](https://cs.android.com/search?q=file:androidx/navigation/dynamicfeatures/NavHost.kt+function:createGraph) Added in [2.3.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.3.0) Deprecated in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
public static final @NonNull NavGraph [createGraph](https://developer.android.com/reference/androidx/navigation/dynamicfeatures/NavHostKt#(androidx.navigation.NavHost).createGraph(kotlin.Int,kotlin.Int,kotlin.Function1))(
    @NonNull NavHost receiver,
    @IdRes int id,
    @IdRes int startDestination,
    @NonNull Function1<@NonNull DynamicNavGraphBuilder, Unit> builder
)
```

> [!CAUTION]
> **This method is deprecated.**   
> Use routes to create your dynamic NavGraph instead, use this instead:
>
> ```
> createGraph(startDestination = startDestination.toString(), route = id.toString()) { builder.invoke() }
> ```

Construct a new `https://developer.android.com/reference/androidx/navigation/NavGraph` that supports dynamic navigation destinations

### createGraph

Artifact: [androidx.navigation:navigation-dynamic-features-runtime](https://developer.android.com/jetpack/androidx/releases/navigation) [View Source](https://cs.android.com/search?q=file:androidx/navigation/dynamicfeatures/NavHost.kt+function:createGraph) Added in [2.4.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.4.0)

```
public static final @NonNull NavGraph createGraph(
    @NonNull NavHost receiver,
    @NonNull String startDestination,
    String route,
    @NonNull Function1<@NonNull DynamicNavGraphBuilder, Unit> builder
)
```

Construct a new `https://developer.android.com/reference/androidx/navigation/NavGraph` that supports dynamic navigation destinations

### createGraph

Artifact: [androidx.navigation:navigation-dynamic-features-runtime](https://developer.android.com/jetpack/androidx/releases/navigation) [View Source](https://cs.android.com/search?q=file:androidx/navigation/dynamicfeatures/NavHost.kt+function:createGraph) Added in [2.8.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.8.0)

```
public static final @NonNull NavGraph createGraph(
    @NonNull NavHost receiver,
    @NonNull Object startDestination,
    KClass<@NonNull ?> route,
    @NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap,
    @NonNull Function1<@NonNull DynamicNavGraphBuilder, Unit> builder
)
```

Construct a new `https://developer.android.com/reference/androidx/navigation/NavGraph` that supports dynamic navigation destinations

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html startDestination` | the starting destination's route from an Object for this NavGraph. The respective NavDestination must be added as a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html` in order to match. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> route` | the graph's unique route from a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-type/index.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavType<@https://developer.android.com/reference/androidx/annotation/NonNull ?>> typeMap` | A mapping of KType to custom NavType\<\*\> in the `https://developer.android.com/reference/androidx/navigation/dynamicfeatures/package-summary#(androidx.navigation.NavHost).createGraph(kotlin.Any,kotlin.reflect.KClass,kotlin.collections.Map,kotlin.Function1)`. May be empty if `https://developer.android.com/reference/androidx/navigation/dynamicfeatures/package-summary#(androidx.navigation.NavHost).createGraph(kotlin.Any,kotlin.reflect.KClass,kotlin.collections.Map,kotlin.Function1)` does not use custom NavTypes. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/dynamicfeatures/DynamicNavGraphBuilder, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> builder` | the builder used to construct the graph |

### createGraph

Artifact: [androidx.navigation:navigation-dynamic-features-runtime](https://developer.android.com/jetpack/androidx/releases/navigation) [View Source](https://cs.android.com/search?q=file:androidx/navigation/dynamicfeatures/NavHost.kt+function:createGraph) Added in [2.8.0](https://developer.android.com/jetpack/androidx/releases/navigation#2.8.0)

```
public static final @NonNull NavGraph createGraph(
    @NonNull NavHost receiver,
    @NonNull KClass<@NonNull ?> startDestination,
    KClass<@NonNull ?> route,
    @NonNull Map<@NonNull KType, @NonNull NavType<@NonNull ?>> typeMap,
    @NonNull Function1<@NonNull DynamicNavGraphBuilder, Unit> builder
)
```

Construct a new `https://developer.android.com/reference/androidx/navigation/NavGraph` that supports dynamic navigation destinations

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> startDestination` | the starting destination's route from a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html` for this NavGraph. The respective NavDestination must be added as a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html` in order to match. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> route` | the graph's unique route from a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-class/index.html` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Map.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.reflect/-k-type/index.html, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/NavType<@https://developer.android.com/reference/androidx/annotation/NonNull ?>> typeMap` | A mapping of KType to custom NavType\<\*\> in the `https://developer.android.com/reference/androidx/navigation/dynamicfeatures/package-summary#(androidx.navigation.NavHost).createGraph(kotlin.reflect.KClass,kotlin.reflect.KClass,kotlin.collections.Map,kotlin.Function1)`. May be empty if `https://developer.android.com/reference/androidx/navigation/dynamicfeatures/package-summary#(androidx.navigation.NavHost).createGraph(kotlin.reflect.KClass,kotlin.reflect.KClass,kotlin.collections.Map,kotlin.Function1)` does not use custom NavTypes. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/navigation/dynamicfeatures/DynamicNavGraphBuilder, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> builder` | the builder used to construct the graph |