swiftui – iOS Widget multiple deeplinking path using widgetURL

0
75


I have a .systemMedium widget. There are 2 vstack to navigate to different view in the app (view deep linking)

The problem is when I press the first vstack, it kept on redirecting to the Button2Path instead of Button1Path:

var body: some View {

        HStack(alignment: VerticalAlignment.top) {
            Spacer()

            VStack {
                Button {
                    print("button 1 was tapped")
                } label: {
                    Image("BtnView1")
                }
                Text("button 1")
            }.widgetURL(URL(string: "testApp://Button1Path"))

            Spacer()

            VStack {
                Button {
                    print("button 2 was tapped")
                } label: {
                    Image("BtnView2")
                }
                Text("button 2")
            }.widgetURL(URL(string: "testApp://Button2Path"))
        }
 }

Check the docs on widgetURL it says “Sets the URL to open in the containing app when the user clicks the widget.”

Are there any other way to achieve this please?

Is it by using Link? how to use it with Vstack?

    Link(destination: URL(string: "testApp://Button1Path")!) {
        Text("Link 1")
    }