角度5:无法在“历史记录"上执行"replaceState":无法在源为"null"的文档中创建具有URL的历史记录状态对象 [英] Angular 5 : Failed to execute 'replaceState' on 'History': A history state object with URL cannot be created in a document with origin 'null'

查看:63
本文介绍了角度5:无法在“历史记录"上执行"replaceState":无法在源为"null"的文档中创建具有URL的历史记录状态对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序的构建--prod上,当从根目录加载index.html或由服务器托管时,出现此错误:

On build --prod of my app I get this error when loading the index.html from a root dir or when hosted by a server :

ERROR Error: Uncaught (in promise): SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'file:///G:/#/' cannot be created in a document with origin 'null' and URL 'file:///G:/index.html'.
Error: Failed to execute 'replaceState' on 'History': A history state object with URL 'file:///G:/#/' cannot be created in a document with origin 'null' and URL 'file:///G:/index.html'.
    at e.replaceState (vendor.7c715405490dfd9b75c0.bundle.js:1)
    at e.replaceState (vendor.7c715405490dfd9b75c0.bundle.js:1)
    at t.replaceState (vendor.7c715405490dfd9b75c0.bundle.js:1)
    at t.resetUrlToCurrentUrlTree (vendor.7c715405490dfd9b75c0.bundle.js:1)
    at t.resetStateAndUrl (vendor.7c715405490dfd9b75c0.bundle.js:1)
    at vendor.7c715405490dfd9b75c0.bundle.js:1
    at t.invoke (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
    at Object.onInvoke (vendor.7c715405490dfd9b75c0.bundle.js:1)
    at t.invoke (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
    at e.run (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
    at e.replaceState (vendor.7c715405490dfd9b75c0.bundle.js:1)
    at e.replaceState (vendor.7c715405490dfd9b75c0.bundle.js:1)
    at t.replaceState (vendor.7c715405490dfd9b75c0.bundle.js:1)
    at t.resetUrlToCurrentUrlTree (vendor.7c715405490dfd9b75c0.bundle.js:1)
    at t.resetStateAndUrl (vendor.7c715405490dfd9b75c0.bundle.js:1)
    at vendor.7c715405490dfd9b75c0.bundle.js:1
    at t.invoke (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
    at Object.onInvoke (vendor.7c715405490dfd9b75c0.bundle.js:1)
    at t.invoke (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
    at e.run (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
    at P (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
    at polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
    at t.invokeTask (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
    at Object.onInvokeTask (vendor.7c715405490dfd9b75c0.bundle.js:1)
    at t.invokeTask (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
    at e.runTask (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
    at v (polyfills.ae3fb5d11cc61f1acad9.bundle.js:1)
    at <anonymous>
kt @ vendor.7c715405490dfd9b75c0.bundle.js:1
t.handleError @ vendor.7c715405490dfd9b75c0.bundle.js:1
next @ vendor.7c715405490dfd9b75c0.bundle.js:1
e.object.i @ vendor.7c715405490dfd9b75c0.bundle.js:1
e.__tryOrUnsub @ vendor.7c715405490dfd9b75c0.bundle.js:1
e.next @ vendor.7c715405490dfd9b75c0.bundle.js:1
e._next @ vendor.7c715405490dfd9b75c0.bundle.js:1
e.next @ vendor.7c715405490dfd9b75c0.bundle.js:1
e.next @ vendor.7c715405490dfd9b75c0.bundle.js:1
e.emit @ vendor.7c715405490dfd9b75c0.bundle.js:1
(anonymous) @ vendor.7c715405490dfd9b75c0.bundle.js:1
t.invoke @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
e.run @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
t.runOutsideAngular @ vendor.7c715405490dfd9b75c0.bundle.js:1
onHandleError @ vendor.7c715405490dfd9b75c0.bundle.js:1
t.handleError @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
e.runGuarded @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
t @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
n.microtaskDrainDone @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
v @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
Promise.then (async)
d @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
t.scheduleTask @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
e.scheduleTask @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
e.scheduleMicroTask @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
O @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
t.then @ polyfills.ae3fb5d11cc61f1acad9.bundle.js:1
t.bootstrapModule @ vendor.7c715405490dfd9b75c0.bundle.js:1
x35b @ main.991a69005f6003446625.bundle.js:1
t @ inline.31e1fb380eb7cf3d75b1.bundle.js:1
0 @ main.991a69005f6003446625.bundle.js:1
t @ inline.31e1fb380eb7cf3d75b1.bundle.js:1
window.webpackJsonp @ inline.31e1fb380eb7cf3d75b1.bundle.js:1
(anonymous) @ main.991a69005f6003446625.bundle.js:1

我不明白这一点,因为即使我打开index.html并手动对其进行编辑 <script>document.write('<base href="./" />')<base href="./">错误仍然存​​在.

I don't understand this because even when I open index.html and manually edit it here : <script>document.write('<base href="./" />') and here <base href="./"> the error persists.

请给我一个指南,以避免这种错误.

please give me a guide to avoid this sort of error.

推荐答案

不能将角项目简单地放在硬盘驱动器或虚拟根驱动器上,并双击它们的index.html.这将显示该页面,但它会识别出该页面尚未由某种服务器提供".

Angular projects can't be simply placed on a hard drive or virtual root drive and have their index.html double clicked on. this will show the page but it will recognize it has not been "served" by some sort of server.

不要这样做.

相反,将您的应用程序与tomcat或某些其他服务器软件捆绑在一起,它将负责运行它.这样,将有一个原点.

Instead bundle your app with tomcat or some other server software and that will be responsible for running it. in this manner there will be an origin point.

这篇关于角度5:无法在“历史记录"上执行"replaceState":无法在源为"null"的文档中创建具有URL的历史记录状态对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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