function getScrollPosition() { var state = _historyLibDOMStateStorage.readState(currentKey); if (!state) { return null; } return state.scrollPosition; }
savePositionHandle = _domHelpersUtilRequestAnimationFrame2['default'](function () { savePositionHandle = null; var state = _historyLibDOMStateStorage.readState(currentKey); var scrollPosition = [_domHelpersQueryScrollLeft2['default'](window), _domHelpersQueryScrollTop2['default'](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. _historyLibDOMStateStorage.saveState(currentKey, _extends({}, state, { scrollPosition: scrollPosition })); });
// Re-render the app when window.location changes 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 }
// Re-render the app when window.location changes function onLocationChange(location) { // Save the page scroll position into the current location's state if (currentLocation && currentLocation.key) { saveState(currentLocation.key, { ...readState(currentLocation.key), scrollX: windowScrollX(), scrollY: windowScrollY(), }); } currentLocation = location; ReactDOM.render( <ContextHolder context={context}> <Router history={history} routes={routes} /> </ContextHolder>, container, renderComplete ); }
read(location, key) { return readState(this.getStateKey(location, key)); }