Search code examples
swiftxcodeangularwkwebviewrouterlink

How to pass an Angular routerLink to a WKWebview with Swift


I have a Angular Web Application that I am working on creating a WKWebview hybrid app from.

It is a fairly basic app with 4 buttons on the bottom that pass a parameter to the WKWebView to open either the Main, Profile, Chat or Settins page of the screen and a WKWEbView dominating the rest of the View Controller.

This is my first time doing this for an Angular Application and what I have come to realize is that using the 4 buttons on the bottom to pass URL's to the WKWebView forces the WebView to reload the bundle.js file each time so I should really pass routerLinks to the Angular application instead of passing URL's to the WebView.

Below is the code I'm using to pass the chat URL to the WebView via an outlet:

    @IBAction func chatURLBtn(_ sender: Any) {

    webUrl = NSURL(string: "http://test.com/messages")!
    let webRequest : NSURLRequest = NSURLRequest(url: self.webUrl as URL)
    webView2.load(webRequest as URLRequest)

}        

Is there any changes I can make here to use the Angular application to ensure that I pass routerLinks instead of URL's?


Solution

  • I ended up solving this one by creating the menu bar in the angular app as well, but I'm sure there is a way to pass routerLinks to WKWebView