Using NavigationLink
i'm attempting to make a button that forwards you to a website on safari, but currently i'm getting the issue Generic struct 'NavigationLink' requires that 'URL' conform to 'View'
from the following line of code
NavigationLink("Website", destination: URL(string: "https://www.google.com")!)
Does anyone know if there's a simple fix to this? tried looking around and didn't find too many resources on it unfortunately.
Thanks in advance!
CodePudding user response:
Use Link
instead of NavigationLink
Link
is for websites, NavigationLink
is for SwiftUI Views.
CodePudding user response:
As i can see there is already a good answer here, but i will write how you should use the Link. As mentioned, NavigationLink is used for navigation between SwiftUI views. Link
is what you need for opening external links.
Link(destination: URL(string: "https://www.google.com")!) {
Text("Website")
}