iOS11 Cordova Angular 4包装打破了SecurityError:history.replaceState() [英] iOS11 Cordova Angular 4 wrap breaking SecurityError: history.replaceState()

查看:292
本文介绍了iOS11 Cordova Angular 4包装打破了SecurityError:history.replaceState()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用cordova包装的angular 4应用程序,在iOS11.1之前运行得很好

I have an angular 4 application wrapped with cordova that was working perfectly fine before iOS11.1

将手机升级到iOS11.1现在我收到错误消息
Error: Uncaught (in promise): SecurityError (DOM Exception 18): Blocked attempt to use history.replaceState() to change session history URL from file:///var/containers/Bundle/Application/CE4A6135-633D-49B9-9A1D-28CBFF5AB832/MyAppName.app/www/index.html to file:///var/containers/Bundle/Application/CE4A6135-633D-49B9-9A1D-28CBFF5AB832/MyAppName.app/www/. Paths and fragments must match for a sandboxed document. replaceState@[native code] replaceState@file:///var/containers/Bundle/Application/CE4A6135-633D-49B9-9A1D-28CBFF5AB832/Real%20Yeti.app/www/

Upgrading the phone to iOS11.1 I now receive the error
Error: Uncaught (in promise): SecurityError (DOM Exception 18): Blocked attempt to use history.replaceState() to change session history URL from file:///var/containers/Bundle/Application/CE4A6135-633D-49B9-9A1D-28CBFF5AB832/MyAppName.app/www/index.html to file:///var/containers/Bundle/Application/CE4A6135-633D-49B9-9A1D-28CBFF5AB832/MyAppName.app/www/. Paths and fragments must match for a sandboxed document. replaceState@[native code] replaceState@file:///var/containers/Bundle/Application/CE4A6135-633D-49B9-9A1D-28CBFF5AB832/Real%20Yeti.app/www/

我的基本标记如下<base href="./">

从外观上看,它在url上进行了字符串比较,并认为我正在尝试访问沙盒区域之外的内容,并将其阻止

From the looks of it is that it does a string compare on the url and thinks I am trying to access outside of the sandboxed area, and blocks it

但是我确实需要指定基本的href,否则所有链接等都将基于电话的根目录(而不是app文件夹)并中断.

I do however need a base href to be specified, otherwise all links etc will be based from the root of the phone (instead of the app folder) and break.

有人知道如何解决此问题吗?
(iOS11.1.1,iOS11.2中存在问题)

Does anyone know how to fix this?
(issue is present with iOS11.1.1, iOS11.2)

推荐答案

我已经使用HashLocationStrategy解决了这一问题.
这将通过/#/加载网址,而不会触发错误.

I have solved this one by using HashLocationStrategy.
This will load the url via /#/ which doesn't trigger the error.

我更改的是:

在index.html中,将基本href设置为#

In index.html set base href to #

<base href="#">

在app-routing.module.ts中添加了useHash选项

In app-routing.module.ts added the useHash option

RouterModule.forRoot( routes, { useHash: true } ),

在app.module.ts中,确保RoutingModule是导入数组中的最后一个

In app.module.ts made sure the RoutingModule is the last in the imports array

imports: [
    ...,
    AppRoutingModule,
],

这篇关于iOS11 Cordova Angular 4包装打破了SecurityError:history.replaceState()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆