Skip to content

Commit

Permalink
feat: support routeChangeError
Browse files Browse the repository at this point in the history
  • Loading branch information
lbwa committed Apr 6, 2021
1 parent b37ee2c commit ea4a19f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/next/client/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ coreMethodFields.forEach((field: string) => {
}
})

routerEvents.forEach((event: RouterEvent) => {
routerEvents.forEach((event) => {
singletonRouter.ready(() => {
Router.events.on(event, (...args) => {
Router.events.on(event as any, (...args: any[]) => {
const eventField = `on${event.charAt(0).toUpperCase()}${event.substring(
1
)}`
Expand Down
23 changes: 15 additions & 8 deletions packages/next/next-server/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,19 @@ type ComponentLoadCancel = (() => void) | null

type HistoryMethod = 'replaceState' | 'pushState'

type RouterEventEmitter = MittEmitter<
Exclude<RouterEvent, 'routeChangeError'>,
(url: string, routeProps: { shallow: boolean }) => void
> &
MittEmitter<
'routeChangeError',
(
err: Error & { cancelled: boolean },
url: string,
routeProps: { shallow: boolean }
) => void
>

const manualScrollRestoration =
process.env.__NEXT_SCROLL_RESTORATION &&
typeof window !== 'undefined' &&
Expand Down Expand Up @@ -505,10 +518,7 @@ export default class Router implements BaseRouter {
clc: ComponentLoadCancel
pageLoader: any
_bps: BeforePopStateCallback | undefined
events: MittEmitter<
RouterEvent,
(url: string, routeProps: { shallow: boolean }) => void
> = mitt()
events: RouterEventEmitter = mitt()
_wrapApp: (App: AppComponent) => any
isSsr: boolean
isFallback: boolean
Expand All @@ -524,10 +534,7 @@ export default class Router implements BaseRouter {

private _idx: number = 0

static events: MittEmitter<
RouterEvent,
(url: string, routeProps: { shallow: boolean }) => void
> = mitt()
static events: RouterEventEmitter = mitt()

constructor(
pathname: string,
Expand Down

0 comments on commit ea4a19f

Please sign in to comment.