From 0b1d23077909d16dfd68ea0fd3ab21c9f461f690 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaenchik Date: Fri, 23 Nov 2018 11:52:36 +0100 Subject: [PATCH] Makes Router singleton again --- src/Routes.tsx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/Routes.tsx b/src/Routes.tsx index e6fe2dad..5c2c6541 100644 --- a/src/Routes.tsx +++ b/src/Routes.tsx @@ -16,7 +16,7 @@ type FnType = ( options?: NextRouteOptions ) => void -type RouterType = typeof NextRouter & { +interface RouterType extends SingletonRouter { pushRoute: FnType replaceRoute: FnType prefetchRoute: FnType @@ -53,7 +53,7 @@ export default class Routes { constructor({ locale }: ConstructorProps) { this.routes = [] this.Link = this.getLink(NextLink) - this.Router = this.getRouter(NextRouter) + this.Router = this.getRouter(NextRouter as RouterType) this.locale = locale } @@ -193,7 +193,7 @@ export default class Routes { return LinkRoutes } - public getRouter(Router: SingletonRouter): RouterType { + public getRouter(Router: RouterType) { const wrap = (method: string) => ( route: string, params: any, @@ -210,11 +210,10 @@ export default class Routes { return Router[method](href, as, byName ? options2 : params) } - return { - ...Router, - pushRoute: wrap('push'), - replaceRoute: wrap('replace'), - prefetchRoute: wrap('prefetch') - } + Router.pushRoute = wrap('push') + Router.replaceRoute = wrap('replace') + Router.prefetchRoute = wrap('prefetch') + + return Router } }