SwiftUI AttributedString handle link opening.

Recently found this https://developer.apple.com/forums/thread/681875#reply-to-this-question, thread seems blocked but I got the answer so I post here:

@Environment(\.openURL) var openURL

var body: .......

Text(someAttributedStringWithLink)         
     .environment(\.openURL, OpenURLAction { url in
           print(url) // do what you like
           return .handled  // compiler won't launch Safari
    })
SwiftUI AttributedString handle link opening.
 
 
Q