widgetURL is override inside Foreach

I am displaying 3 rows in medium size widget like below:
Code Block
row 1
-------
row 2
-------
row 3
-------


my view structure is here:
Code Block
VStack {
ForEach(records, id: \.id) { item in
ZStack {
// some views
}
.widgetURL(URL(string: "wig://\(item.id)"))
}
Divider()
}


It seems the widget URL for first and second items are override by the the third item, all deep link will open third item's content.

what is the proper way to add deep link for views generated from ForEach?
Answered by Claude31 in 640463022
Did you read doc for widgetURL

Widgets support one widgetURL modifier in their view hierarchy. If multiple views have widgetURL modifiers, the behavior is undefined.

It seems you fall in this case.
What are exactly items in records ? Please show records definition.

Did you try to manually open each "wig://\(item.id)" ?

Could you print "wig://\(item.id)" somewhere ?
Accepted Answer
Did you read doc for widgetURL

Widgets support one widgetURL modifier in their view hierarchy. If multiple views have widgetURL modifiers, the behavior is undefined.

It seems you fall in this case.

Widgets support one widgetURL modifier in their view hierarchy. If multiple views have widgetURL modifiers, the behavior is undefined.

@Claude31

Thanks for the reply, you are right.

The record is a list of data structure, with unique identifier for each record, like
Code Block
struct UserRecord {
id: String
title: String
}

The deep link url looks like this: wig://1602639386. Manually open one url is working.

Hmmm, let me see if any other approach can achieve this.
one way to achieve it is using Link:
Code Block
ForEach(records, id: \.id) { item in
Link(destination: URL(string: "wig://\(item.id)")!) {
ZStack {
// some views
}
}
}

widgetURL is override inside Foreach
 
 
Q