Ios SecurityError(DOM异常18):阻止尝试使用history.replaceState()。。。角度5 问题

Ios SecurityError(DOM异常18):阻止尝试使用history.replaceState()。。。角度5 问题,ios,swift,Ios,Swift,我收到以下错误: [Error]Error–Error:Uncaught(承诺中):SecurityError(DOM异常18):阻止尝试使用history.replaceState()更改会话历史URL的步骤file:///Users//Library/Developer/CoreSimulator/Devices//data/Containers/Bundle/Application//ios-shell.app/public/index.html 到file:///Users//Libra

我收到以下错误:

[Error]Error–Error:Uncaught(承诺中):SecurityError(DOM异常18):阻止尝试使用history.replaceState()更改会话历史URL的步骤file:///Users//Library/Developer/CoreSimulator/Devices//data/Containers/Bundle/Application//ios-shell.app/public/index.html 到file:///Users//Library/Developer/CoreSimulator/Devices//data/Containers/Bundle/Application//ios-shell.app/public/#/. 路径和片段必须与沙盒文档匹配

这两个URL之间的区别只是结尾
public/index.html
->
public/#/

然而,在
文件://
文件://

实施 这是一个定制的iOS应用程序,创建该应用程序是为了在不使用cordova的情况下运行HTML SPA应用程序。当前使用
WKWebView在iOS 11.2上的iPhone 8设备上的模拟器中运行

web应用程序是一个Angular 5应用程序,使用
{hash:true}
作为路由策略

视图控制器

class ViewController: UIViewController {
    var serenity: Serenity?

    override func viewDidLoad() {
        super.viewDidLoad()
        serenity = Serenity(self)
        serenity?.load("index")
    }

    ...
}
宁静。迅捷

class Serenity: WKWebView, WKScriptMessageHandler{

    var controller: ViewController?
    let config = WKWebViewConfiguration()
    var commands = Dictionary<String, (_ args: Any?) -> Any?>()

    init(_ controller: ViewController){
        self.controller = controller
        config.userContentController.addUserScript(WKUserScript(source: "window.NATIVE_DEVICE=true;", injectionTime: WKUserScriptInjectionTime.atDocumentStart, forMainFrameOnly: false))
        super.init(frame: controller.view.frame, configuration: config)
    }

    func load(_ file: String) {
        if let html = Bundle.main.path(forResource: file, ofType: "html", inDirectory: "public"){
            let url = URL(fileURLWithPath: html)
            let request = URLRequest(url: url)
            super.load(request)
            controller?.view.addSubview(self)
        }
    }

    ...
}
class Serenity:WKWebView、WKScriptMessageHandler{
变量控制器:视图控制器?
让config=WKWebViewConfiguration()
var commands=Dictionary Any?>()
init(u控制器:ViewController){
self.controller=控制器
config.userContentController.addUserScript(WKUserScript(来源:“window.NATIVE_DEVICE=true;”,injectionTime:WKUserScriptInjectionTime.atDocumentStart,FormInframeOnly:false))
super.init(frame:controller.view.frame,配置:config)
}
func加载(u文件:字符串){
如果让html=Bundle.main.path(forResource:file,of type:“html”,inDirectory:“public”){
让url=url(fileURLWithPath:html)
let request=URLRequest(url:url)
超级加载(请求)
控制器?.view.addSubview(自)
}
}
...
}
问题

是否有办法将
index.html
文件加载为
public/
,以便angular接管并开始布线时不会导致此错误

任何其他建议也会有帮助

解决方案 我修改了index.html文件,使其具有
的基,而不是
,这迫使angular使用
../index.html/#/
等路由,而不是
../code>

非解决方案(针对未来搜索者) 我试图加载目录,默认情况下允许
WKWebView
加载index.html页面

if let html = Bundle.main.path(forResource: file, ofType: "html", inDirectory: "public"){
    let url = URL(fileURLWithPath: html)
    let request = URLRequest(url: url).deletingLastPathComponent()
    super.load(request)
    controller?.view.addSubview(self)
}
但是,这导致
WKWebView
根本无法加载页面