Skip to content

Commit

Permalink
Make sure to follow correct route change order
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Feb 5, 2020
1 parent 591b4a0 commit efd508b
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions packages/next/next-server/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,23 +393,25 @@ export default class Router implements BaseRouter {

// If shallow is true and the route exists in the router cache we reuse the previous result
this.getRouteInfo(route, pathname, query, as, shallow).then(routeInfo => {
const { error } = routeInfo
const doRouteChange = (routeInfo: RouteInfo, emit: boolean) => {
const { error } = routeInfo

if (error && error.cancelled) {
return resolve(false)
}
if (error && error.cancelled) {
return resolve(false)
}

Router.events.emit('beforeHistoryChange', as)
this.changeState(method, url, addBasePath(as), options)
if (emit) {
Router.events.emit('beforeHistoryChange', as)
this.changeState(method, url, addBasePath(as), options)

if (process.env.NODE_ENV !== 'production') {
const appComp: any = this.components['/_app'].Component
;(window as any).next.isPrerendered =
appComp.getInitialProps === appComp.origGetInitialProps &&
!(routeInfo.Component as any).getInitialProps
}
if (process.env.NODE_ENV !== 'production') {
const appComp: any = this.components['/_app'].Component
;(window as any).next.isPrerendered =
appComp.getInitialProps === appComp.origGetInitialProps &&
!(routeInfo.Component as any).getInitialProps
}
}

const doRouteChange = (routeInfo: RouteInfo, emit: boolean) => {
this.set(route, pathname, query, as, routeInfo)

if (emit) {
Expand Down

0 comments on commit efd508b

Please sign in to comment.