Skip to content

Commit

Permalink
Makes Router singleton again
Browse files Browse the repository at this point in the history
  • Loading branch information
favorit authored Nov 23, 2018
1 parent e5f27a8 commit 0b1d230
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type FnType = (
options?: NextRouteOptions
) => void

type RouterType = typeof NextRouter & {
interface RouterType extends SingletonRouter {
pushRoute: FnType
replaceRoute: FnType
prefetchRoute: FnType
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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,
Expand All @@ -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
}
}

0 comments on commit 0b1d230

Please sign in to comment.