(callback)
| 1 | |
| 2 | export 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected