2017-01-31 60 views
0

我试图运行angularjs 2应用程序dist文件作为简单的html页面。即我只需双击dist文件夹中的index.html即可。但是,应用程序无法正常工作:错误:angularjs 2:SecurityError:无法执行

EXCEPTION: Uncaught (in promise): SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'file:///D:/' cannot be created in a document with origin 'null' and URL 'file:///D:/dev/ProxyVoting/ngapp/dist/index.html'.

+1

你不能只是点击index.html,然后,除了它的工作。您的页面需要一些强制性文件,如果不使用服务器(Apache,node.js,...)则无法访问。 – mickdev

+0

@mickdev你可以描述页面需要什么类型的文件吗?谢谢。 –

+0

有关Angular 2 App生产的更多详细信息,请参阅此处:http://stackoverflow.com/a/38765929/7447071 – mickdev

回答

0

第一步:

运行命令

ng build 

ng build -prod (then it will compact all files for production version) 

第二步:

在变化中的index.html dist目录

<base href="/"> to <base href="./"> 

第三步:

把所有文件到服务器(可以是本地主机或任​​何服务器的htdocs)

希望它会工作。

+0

无法使用此解决方案。 –

1

使用HTTP服务器而不是直接文件访问。我面临同样的问题;所以,我用XAMPP &搞定了。

所以,你index.html将包含base href这样的事情 - <base href="http://localhost:81/etl/">