react history api code example
Example 1: use history in react router
import {createBrowserHistory} from 'history';import {useRouterHistory, Router, Route} from 'react-router';const history = useRouterHistory(createBrowserHistory)({ basename: '/basename'});history.listen(location => { history.push('/super/url');});const router = ( <Router history={history}> <Route path=’/' component={App}> … </Route> </Router>);
Example 2: props history
{
key: 'ac3df4',
pathname: '/somewhere',
search: '?some=search-string',
hash: '#howdy',
state: {
[userDefined]: true
}
}