0
我有角度cli創建的dist文件夾。現在,我想在不提供任何服務器的情況下運行這些文件。如何運行沒有服務器的Angular 4生產代碼
的index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Demo</title>
<base href="./">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link href="styles.076e9918da4cedd3d6c1.bundle.css" rel="stylesheet"/></head>
<body>
<app-root>Loading...</app-root>
<script type="text/javascript" src="inline.44e099ae9c80ebe794de.bundle.js"></script><script type="text/javascript" src="polyfills.aa13f035adb29aecad16.bundle.js"></script><script type="text/javascript" src="vendor.5a179b7fcba087187492.bundle.js"></script><script type="text/javascript" src="main.1b6029e74c79858144e5.bundle.js"></script></body>
</html>
在<base href ="/">
情況下,我沒有得到js和他人的index.html文件捆綁。 如果我改變<base href ="/">
到<base href ="./">
,然後得到以下 錯誤:
ERROR Error: Uncaught (in promise): SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'file:///root/Downloads/Client%20demo%20project/dist/' cannot be created in a document with origin 'null' and URL 'file:///root/Downloads/Client%20demo%20project/dist/index.html'.
Error: Failed to execute 'replaceState' on 'History': A history state object with URL 'file:///root/Downloads/Client%20demo%20project/dist/' cannot be created in a document with origin 'null' and URL 'file:///root/Downloads/Client%20demo%20project/dist/index.html'.
「沒有提供任何服務器」是什麼意思?你想直接從磁盤加載到瀏覽器中? Chrome有幾個安全限制,並且在從磁盤而不是從服務器加載文件時阻止了幾件事情。 Angular沒有太多可以做的事情。 –
' 由路由使用,你可以閱讀這個[doc](https://angular.io/docs/ts/latest/guide/router.html#!#base-href ) –