Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function onLocationChange(location) {
// Save the page scroll position into the current location's state
if (currentLocation.key) {
saveState(currentLocation.key, {
...readState(currentLocation.key),
scrollX: windowScrollX(),
scrollY: windowScrollY(),
});
}
currentLocation = location;
UniversalRouter.resolve(routes, {
path: location.pathname,
query: location.query,
state: location.state,
context,
render: render.bind(undefined, container, location), // eslint-disable-line react/jsx-no-bind, max-len
}).catch(err => console.error(err)); // eslint-disable-line no-console
}
savePositionHandle = requestAnimationFrame(() => {
savePositionHandle = null
const state = readState(currentKey)
const scrollPosition = [ scrollLeft(window), scrollTop(window) ]
// We have to directly update `DOMStateStorage`, because actually
// updating the location could cause e.g. React Router to re-render the
// entire page, which would lead to observably bad scroll performance.
saveState(currentKey, { ...state, scrollPosition })
})
}
readPosition(location, key) {
return readState(this._getKey(location, key));
}
function get_history_state_location(history_state)
{
const key = history_state && history_state.key
return createLocation
({
pathname : window.location.pathname,
search : window.location.search,
hash : window.location.hash,
state : key ? readState(key) : undefined
},
undefined,
key)
}
export function get_from_history(prefix, key)
{
return readState(compute_key(prefix, key))
}