This guide covers various navigation methods using the Navigator
class.
Leverage SwiftUI's NavigationLink
with navigationDestination
.
struct ContentView: View {
var body: some View {
Navigation(
root: {
List {
NavigationLink(value: DetailViewData()) {
Text("Detail View")
}
}
}
)
.navigationDestination(
for: DetailViewData.self,
destination: { data in
DetailView(data: data)
}
)
}
}
Programmatically navigate by modifying the Navigator
's path.
struct ContentView: View {
@EnvironmentObject var navigator: Navigator
var body: some View {
Button(
action: {
navigator.append(
DetailViewData()
)
},
label: {
Text("Go to Detail View")
}
)
}
}
Use NavigatorButton
for a concise navigation button.
struct ContentView: View {
var body: some View {
NavigatorButton(
destination: DetailViewData(),
label: {
Text("Navigate to Detail View")
}
)
}
}
Ready to unlock the full power of Navigation? Dive into advanced topics like custom navigation paths and deep linking.