All notes
History

Basics

npmjs.com: history.

Three types

Usage

import or require



// using ES6 modules
import createHistory from 'history/createBrowserHistory'
 
// using CommonJS modules
var createHistory = require('history').createBrowserHistory

example



import createHistory from 'history/createBrowserHistory'
 
const history = createHistory()
 
// Get the current location.
const location = history.location
 
// Listen for changes to the current location.
const unlisten = history.listen((location, action) => {
  // location is an object like window.location
  console.log(action, location.pathname, location.state)
})
 
// Use push, replace, and go to navigate around.
history.push('/home', { some: 'state' })
 
// To stop listening, call the function returned from listen().
unlisten()

forceRefresh

By default createBrowserHistory uses HTML5 pushState and replaceState to prevent reloading the entire page from the server while navigating around. If instead you would like to reload as the URL changes, use the forceRefresh option.


// Forcing Full Page Refreshes in createBrowserHistory
const history = createBrowserHistory({
  forceRefresh: true
})