Uncaught SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL
Uncaught SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL
我使用 webpack (1.12.2)、react (0.14.2)、react-router (1.0.0-rc4) 和 history (1.13.0) 库。
当我使用 webpack 构建项目时,在 google chrome 控制台中出现错误:
Uncaught SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'file:///Users/and/devel/Wond/index.html' cannot be created in a document with origin 'null'.
在 createBrowserHistory.js 第 41 行。
在我的源代码 (index.jsx) 中,我使用 createBrowserHistory:
var createBrowserHistory = require('history/lib/createBrowserHistory');
let history = createBrowserHistory();
ReactDOM.render(<Router routes={routes} history={history} />, document.getElementById('content'));
您的文档具有 origin 'null'
,因为您是从文件方案 URI 加载它的。
安装网络服务器并从那里加载您的 HTML 文档。
详细说明昆汀的回答。您可以 运行 在网络服务器上使用:
npx http-server Wond_dist
其中 Wond_dist
是 public 或分发文件夹。
您可以在此处阅读有关 http-server 的更多信息:https://github.com/http-party/http-server
在这个 post 中,您还可以 运行 使用更多的 Web 服务器:Using Node.js as a simple web server
我使用 webpack (1.12.2)、react (0.14.2)、react-router (1.0.0-rc4) 和 history (1.13.0) 库。
当我使用 webpack 构建项目时,在 google chrome 控制台中出现错误:
Uncaught SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'file:///Users/and/devel/Wond/index.html' cannot be created in a document with origin 'null'.
在 createBrowserHistory.js 第 41 行。
在我的源代码 (index.jsx) 中,我使用 createBrowserHistory:
var createBrowserHistory = require('history/lib/createBrowserHistory');
let history = createBrowserHistory();
ReactDOM.render(<Router routes={routes} history={history} />, document.getElementById('content'));
您的文档具有 origin 'null'
,因为您是从文件方案 URI 加载它的。
安装网络服务器并从那里加载您的 HTML 文档。
详细说明昆汀的回答。您可以 运行 在网络服务器上使用:
npx http-server Wond_dist
其中 Wond_dist
是 public 或分发文件夹。
您可以在此处阅读有关 http-server 的更多信息:https://github.com/http-party/http-server
在这个 post 中,您还可以 运行 使用更多的 Web 服务器:Using Node.js as a simple web server