'SwiftUI Deep link for a destination within app?

I figured out Android has a deep link for a specific destination within app. (https://developer.android.com/guide/navigation/navigation-deep-link). However, I don't know how to implement this with SwiftUI which is limited to NavigationView/NavigationLink.

For Example, when tapped a banner it directly goes to Event Tab and a specific event page which is a WebView.

enter image description here

If there is no way to implement it with SwiftUI, I even want to know the way with UIKit. Thanks.



Solution 1:[1]

Use .handlesExternalEvents(preferring:allowing:) and onOpenURL(perform:) as follows:

@main
struct DeepLinkApp: App {    
    var body: some Scene {
        WindowGroup {
            ContentView()
            .handlesExternalEvents(preferring: ["scheme"], allowing: ["scheme"])
        }
    }
}

struct ContentView: View {
    var body: some View {
        NavigationView {

        }
        .onOpenURL{ url in
            // set state from the url
        }
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 malhal