diff --git a/packages/next/client/router.ts b/packages/next/client/router.ts index ad8af87bcf663f098aa32c7ad8786622170965a7..32da8433124f4c614828b376ad63de7d35b0e168 100644 --- a/packages/next/client/router.ts +++ b/packages/next/client/router.ts @@ -13,7 +13,7 @@ type SingletonRouterBase = { ready(cb: () => any): void } -export { Router, RouterContext, NextRouter } +export { Router, NextRouter } export type SingletonRouter = SingletonRouterBase & NextRouter diff --git a/packages/next/client/with-router.tsx b/packages/next/client/with-router.tsx index 968d3ecdccfbe18593dd3bf2c63b4c4ce587fe62..59f50c8dc26f84f06a273a6815c74eaeba08a249 100644 --- a/packages/next/client/with-router.tsx +++ b/packages/next/client/with-router.tsx @@ -1,6 +1,6 @@ import React from 'react' import { NextComponentType, NextPageContext } from '../next-server/lib/utils' -import { NextRouter, RouterContext } from './router' +import { NextRouter, useRouter } from './router' export type WithRouterProps = { router: NextRouter @@ -16,27 +16,19 @@ export default function withRouter< C = NextPageContext >( ComposedComponent: NextComponentType -): React.ComponentClass> { - class WithRouteWrapper extends React.Component> { - static displayName?: string - static getInitialProps?: any - static contextType = RouterContext - - context!: React.ContextType - - render() { - return - } +): React.ComponentType> { + function WithRouterWrapper(props: any) { + return } - WithRouteWrapper.getInitialProps = ComposedComponent.getInitialProps + WithRouterWrapper.getInitialProps = ComposedComponent.getInitialProps // This is needed to allow checking for custom getInitialProps in _app - ;(WithRouteWrapper as any).origGetInitialProps = (ComposedComponent as any).origGetInitialProps + ;(WithRouterWrapper as any).origGetInitialProps = (ComposedComponent as any).origGetInitialProps if (process.env.NODE_ENV !== 'production') { const name = ComposedComponent.displayName || ComposedComponent.name || 'Unknown' - WithRouteWrapper.displayName = `withRouter(${name})` + WithRouterWrapper.displayName = `withRouter(${name})` } - return WithRouteWrapper + return WithRouterWrapper }