2019-01-14 14:41:09 +00:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2017-08-30 14:07:12 +00:00
|
|
|
import hoistStatics from 'hoist-non-react-statics'
|
2018-11-28 14:03:02 +00:00
|
|
|
import { getDisplayName } from 'next-server/dist/lib/utils'
|
2017-08-30 14:07:12 +00:00
|
|
|
|
2017-08-31 19:37:20 +00:00
|
|
|
export default function withRouter (ComposedComponent) {
|
2017-08-30 14:07:12 +00:00
|
|
|
const displayName = getDisplayName(ComposedComponent)
|
|
|
|
|
2019-01-14 14:41:09 +00:00
|
|
|
class WithRouteWrapper extends Component {
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object
|
|
|
|
}
|
|
|
|
|
|
|
|
static displayName = `withRouter(${displayName})`
|
2017-08-30 14:07:12 +00:00
|
|
|
|
2019-01-14 14:41:09 +00:00
|
|
|
render () {
|
|
|
|
return <ComposedComponent
|
|
|
|
router={this.context.router}
|
|
|
|
{...this.props}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
}
|
2019-01-11 15:04:56 +00:00
|
|
|
|
2017-08-30 14:07:12 +00:00
|
|
|
return hoistStatics(WithRouteWrapper, ComposedComponent)
|
|
|
|
}
|