         // Open "target=_blank" in the same view
         if navigationAction.targetFrame == nil {
             // Open same domain links within app
-            if navigationAction.request.url?.host == URL(string: AppGlobal.userDefaults[.baseURL])?.host {
+            if let requestURL = navigationAction.request.url, requestURL.host == URL(string: AppGlobal.userDefaults[.baseURL])?.host {
                 // Deep link to category
-                if let term = TermService().get(navigationAction.request.url), routeToTerm(term.id) {
+                if let term = TermService().get(requestURL), routeToTerm(term.id) {
                     return nil
-                } else if let post = service.get(navigationAction.request.url) {
+                } else if let post = service.get(requestURL) {
                     // Save history and bind retrieved post to current view
                     history.append(model)
                     loadData(post)

        // Handle links
        if navigationAction.navigationType == .linkActivated && navigationAction.targetFrame?.isMainFrame == true {
            // Open same domain links within app
            if navigationAction.request.url?.host == URL(string: AppGlobal.userDefaults[.baseURL])?.host {
                // Deep link to category
                if let term = TermService().get(navigationAction.request.url), routeToTerm(term.id) {
                    return decisionHandler(.cancel)
                } else if let post = service.get(navigationAction.request.url) {
                    // Save history and bind retrieved post to current view
                    history.append(model)
                    loadData(post)
                    return decisionHandler(.cancel)
                }
            } else if let url = navigationAction.request.url {
                // Open external links in browser
                presentSafariController(url.absoluteString)
                return decisionHandler(.cancel)
            }
            

                }
                
                webView.load(navigationAction.request)
            } else if let requestURL = navigationAction.request.url {
                // Open external links in browser
                presentSafariController(requestURL.absoluteString)
                return nil
            }
            
