简体   繁体   中英

Uncaught SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL

I use webpack (1.12.2), react (0.14.2), react-router (1.0.0-rc4) and history (1.13.0) libraries.

When I build project with webpack, in google chrome console I get error:

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'.

In createBrowserHistory.js line 41.

In my source code (index.jsx) I use createBrowserHistory:

var createBrowserHistory = require('history/lib/createBrowserHistory');
let history = createBrowserHistory();

ReactDOM.render(<Router routes={routes} history={history} />, document.getElementById('content'));

Your document has the origin 'null' because you are loading it from a file scheme URI.

Install a web server and load your HTML document from there.

To elaborate off of Quentin's answer. You can run it on a web server using:

npx http-server Wond_dist

Where Wond_dist is the public or distribution folder.

You can read more about http-server here: https://github.com/http-party/http-server

There are also many more web servers you can run it on in this post: Using Node.js as a simple web server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM