Allow Websites in WKWebView

Hi there! I am developing an app that opens our website in a web view. The issue is that the web view will not open external links (e.x. if the main URL is https://example.com, the app will not open a link to https://example.org ). I have no idea what I am doing and was hoping a smart person here could help me out. Thanks!

import SwiftUI
import WebKit

extension WKWebView {
  func load(_ urlString: String) {

    if let url = URL(string: urlString) {
      let request = URLRequest(url: url)
      load(request)
    }
  }
}

struct WebView : UIViewRepresentable {
  var url: String

  func makeUIView(context: Context) -> WKWebView {
    return WKWebView()
  }

  func updateUIView(_ uiView: WKWebView, context: Context) {
    print(url)
    uiView.load(url)
  }
}

struct ContentView: View {
  var body: some View {
    WebView(url: "https://warehousechurch.life")
  }
}
Answered by zionsnider in 728833022

Nevermind. I found out the issue was that the button was opening in a new tab, and that was what was messing up. I set it to open in the same tab and that solved the issue, so it wasn't the code after all.

Accepted Answer

Nevermind. I found out the issue was that the button was opening in a new tab, and that was what was messing up. I set it to open in the same tab and that solved the issue, so it wasn't the code after all.

Allow Websites in WKWebView
 
 
Q