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 })
})
}
_savePosition(key, element) {
// 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(
this._getKey(this._getCurrentLocation(), key),
[scrollLeft(element), scrollTop(element)]
);
}
function set_location(location, history, method)
{
// A little bit of a fight with `scroll-behavior` here
const key = history.createKey()
// Save the correct `scroll-behavior`'s scroll position
// in this new history entry `scroll-behavior` state.
saveState(`${SCROLL_STATE_KEY_PREFIX}${key}`, get_scroll())
// Set the new `location` `key`
location = history.createLocation(location, method, key)
// Prevent `scroll-behavior` from messing
// with scroll on this location transition
location.scroll = false
// Prevent `react-router` from remounting page component
location.remount = false
// Transition to the new location
history.transitionTo(location)
}
save(location, key, value) {
saveState(this.getStateKey(location, key), value);
}
export function store_in_history(prefix, key, data)
{
return saveState(compute_key(prefix, key), data)
}