Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function changePage(
nextLocation: BatfishLocation,
setRouterState: (state: RouterState, callback: () => void) => void,
options: { pushState?: boolean, scrollToTop?: boolean } = {},
onFinish?: () => mixed
): Promise {
const win = getWindow();
const matchingRoute = findMatchingRoute(nextLocation.pathname);
const nextUrl = [
nextLocation.pathname,
nextLocation.hash,
nextLocation.search
].join('');
// Call the change-start callbacks immediately, not after the page chunk
// has already been fetched.
const startChange = _invokeRouteChangeStartCallbacks(nextLocation.pathname);
return matchingRoute
.getPage()
.then((pageModule) => {
return startChange.then(() => pageModule);
})
.then((pageModule) => {
if (options.pushState) {
win.history.pushState({}, null, nextUrl);
}
const nextState = {
path: matchingRoute.path,
PageComponent: pageModule.component,
pageProps: pageModule.props,
location: getCurrentLocation()
};
setRouterState(nextState, () => {