I am trying to integrate NavigationStack
in my SwiftUI app.
I have four views: CealUIApp
, OnBoardingView
, UserTypeView
and RegisterView
.
I want to navigate from OnBoardingView
to UserTypeView
when user presses a button in OnBoardingView
.
And, navigate from UserTypeView
to RegisterView
when user presses a button in UserTypeView
Below is my code for CealUIApp
@main
struct CealUIApp: App {
@State private var path = [String]()
var body: some Scene {
WindowGroup {
NavigationStack(path: $path){
OnBoardingView(path: $path)
}
}
}
}
In OnBoardingView
Button {
path.append("UserTypeView")
}
label: {
Text("Hello")
}
.navigationDestination(for: String.self) { string in
UserTypeView(path: $path)
}
In UserTypeView
Button {
path.append("RegisterView")
}
label: {
Text("Hello")
}
.navigationDestination(for: String.self) { string in
RegisterView()
}
When the button on UserTypeView
is pressed, it navigates to UserTypeView
instead of RegisterView
.
Also, the Xcode logs saying
Only root-level navigation destinations are effective for a navigation stack with a homogeneous path.