未捕获的安全错误:无法在“历史记录”上执行“replaceState”:带有 URL 的历史状态对象

Mat*_*att 1 javascript reactjs webpack react-router

我使用 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'.
Run Code Online (Sandbox Code Playgroud)

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'));
Run Code Online (Sandbox Code Playgroud)

Que*_*tin 5

您的文档具有 ,origin 'null'因为您是从文件方案 URI 加载它。

安装 Web 服务器并从那里加载 HTML 文档。