A lightweight SwiftUI navigation package that brings NavigationStack-style routing to iOS 14 and iOS 15 while still using native NavigationStack on iOS 16+.
- ✅ Supports iOS 14+
- ✅ Native
NavigationStackon iOS 16+ - ✅ Automatic
NavigationViewfallback on iOS 14/15 - ✅ Route-based navigation
- ✅ Programmatic push/pop APIs
- ✅ Pop to root
- ✅ Deep-link path replacement
- ✅ Mixed-type path navigation
- ✅ Optional state restoration
- ✅ SwiftUI-first API
- ✅ No UIKit wrappers
| Platform | Version |
|---|---|
| iOS | 14.0+ |
| macOS | 12.0+ |
| tvOS | 15.0+ |
| watchOS | 8.0+ |
- Swift 5.9+
- Xcode 15+
Add the package dependency in Xcode:
dependencies: [
.package(
url: "https://github.com/Sakshiing/NavigationStackCompat.git",
from: "1.0.0"
)
]import SwiftUI
import NavigationStackCompat
enum AppRoute: Hashable {
case detail(id: Int)
case settings
}
struct ContentView: View {
@StateObject private var navigator = CompatNavigator<AppRoute>()
var body: some View {
CompatNavigationStack(navigator: navigator) {
List {
CompatNavigationLink(
"Open Detail",
value: AppRoute.detail(id: 42)
)
Button("Open Settings") {
navigator.push(.settings)
}
Button("Reset") {
navigator.popToRoot()
}
}
.compatNavigationDestination(for: AppRoute.self) { route in
switch route {
case .detail(let id):
Text("Detail \(id)")
case .settings:
Text("Settings")
}
}
}
}
}navigator.push(.settings)
navigator.pop()
navigator.popToRoot()
navigator.replacePath(with: [
.detail(id: 1),
.settings
])Use CompatPathNavigator when your navigation path contains multiple value types, similar to SwiftUI's NavigationPath.
iOS 16+ → Native NavigationStack
iOS 14/15 → NavigationView + NavigationLink fallback
The navigator state stays synchronized with the visible navigation hierarchy while supporting:
- system back button
- swipe-to-go-back gestures
- deep-link restoration
- programmatic navigation
Run package tests:
swift testMIT License
See the LICENSE file for details.