# Legacy Navigation Implementation

## SafeArgs Setup

```kotlin
// build.gradle.kts (Project)
dependencies {
    classpath("androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version")
}

// build.gradle.kts (Module)
plugins {
    id("androidx.navigation.safeargs.kotlin")
}
```

## Navigation Graph (nav_graph.xml)

```xml
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:startDestination="@id/homeFragment">

    <fragment
        android:id="@+id/homeFragment"
        android:name="com.example.HomeFragment">
        <action
            android:id="@+id/action_home_to_details"
            app:destination="@id/detailsFragment" />
    </fragment>

    <fragment
        android:id="@+id/detailsFragment"
        android:name="com.example.DetailsFragment">
        <argument
            android:name="postId"
            app:argType="string" />
    </fragment>
</navigation>
```

## Navigate with SafeArgs

```kotlin
// Origin
val action = HomeFragmentDirections.actionHomeToDetails(postId = "123")
findNavController().navigate(action)

// Destination
val args: DetailsFragmentArgs by navArgs()
val postId = args.postId
```

## NavHostFragment Layout Setup

```kotlin
// In Activity layout XML
<fragment
    android:id="@+id/nav_host"
    android:name="androidx.navigation.fragment.NavHostFragment"
    app:navGraph="@navigation/nav_main"
    app:defaultNavHost="true" />
```

## Type-Safe Navigation with SafeArgs

```kotlin
// Type-safe navigation — generated by SafeArgs plugin
val action = HomeFragmentDirections.actionHomeToDetail(itemId = 42)
findNavController().navigate(action)

// Receiving args in destination
val args: DetailFragmentArgs by navArgs()
val itemId = args.itemId
```
