MCPcopy Create free account
hub / github.com/DavidWells/analytics / routeChange

Function routeChange

examples/react/src/utils/routeChanges.js:2–18  ·  view source on GitHub ↗
(callback)

Source from the content-addressed store, hash-verified

1
2export default function routeChange(callback) {
3 const { addEventListener, history, location } = window
4 // Observe native navigation
5 addEventListener('popstate', () => {
6 callback(location.pathname)
7 })
8 // Observe manual navigation
9 const methods = ['push', 'replace']
10 methods.map(type => { // eslint-disable-line
11 const state = `${type}State`;
12 const historyState = history[state];
13 history[state] = function() {
14 callback(arguments[2])
15 return historyState.apply(history, arguments);
16 }
17 })
18}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected