Here is my code ultimately working in UIKit, but the same thing how can I implement it in SwiftUI? Here I can change destination pushViewController
based on my requirements.
/// UIKIt Code
public struct Navigator {
public var onLoginSuccess: (UINavigationController) -> Void = { navigationController in
navigationController.pushViewController(UIViewController(), animated: true)
}
}
/// Usage
var router = Navigator()
router.onLoginSuccess = { nav in
nav.pushViewController(AnyViewController(), animated: true)
}
///Here is my SwiftUI code which is working fine with defined destination, how to accept destination to `onLogin` and `push` to that view?
struct ContentView: View {
var body: some View {
NavigationView {
HStack {
NavigationLink(destination: Router.onLogin) {
Text("HOME")
}
}
}
}
}
struct Router {
@ViewBuilder
static var onLogin: some View {
Text("Hello")
}
}