Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: [history] pushState is deprecated; use push instead

when using a webpack + react + react-router + es6

Warning: [history] pushState is deprecated; use push instead

<pre>
import React from 'react';
import ReactDOM from 'react-dom';
import {createHistory} from 'history';
import App from './component/app';
import About from './component/about';
import Concat from './component/concat';
import List from './component/list';
import {Router, Route} from 'react-router';
const history = createHistory();
const router = (
    <Router history={history}>
        <Route path="/" component={App}>
            <Route path="about" component={About} />
            <Route path="concat" component={Concat} />
            <Route path="list/:id" component={List} />
            <Route path="*" component={About}/>
        </Route>
    </Router>
);

ReactDOM.render(
    router,
    document.getElementById('root')
);
</pre>
like image 652
adin Avatar asked Dec 07 '15 07:12

adin


People also ask

Is history push is deprecated?

New! Save questions or answers and organize your favorite content. Learn more.

What is history pushState?

In an HTML document, the history. pushState() method adds an entry to the browser's session history stack.

How do I stop browser from pushing history?

Open Chrome browser and Click on Menu, under this section tap Settings. In Site settings, again continue to scroll down and choose Notifications. In Notifications section, select the site you want to allow or deny web push services.

What is history replaceState?

The History. replaceState() method modifies the current history entry, replacing it with the state object and URL passed in the method parameters. This method is particularly useful when you want to update the state object or URL of the current history entry in response to some user action.


2 Answers

I had the same issue myself today, it's due to the new merge request to the History repo:

https://github.com/rackt/history/commit/a9db75ac71b645dbd512407d7876799b70cab11c

[TEMP FIX] Update your package.json, change "history" to "1.13.1" in dependencies. Do a "npm install" afterwards to update.

[REAL FIX] Wait until someone merges a fix into react-router.

like image 127
Linus Avatar answered Sep 28 '22 16:09

Linus


In previous versions of History (npm install history) pushState was used. pushState is a feature of HTML5 concerning the updating of the URL without navigating to a page/template/component.

This was deprecated in honor of push('path'), which is a cleaner better syntax according to some.

Replace

this.history.pushState(null, "/route/") 

with

this.history.push('/store/' + storeId);
like image 20
TheBetterJORT Avatar answered Sep 28 '22 15:09

TheBetterJORT