Unverified Commit 355078c3 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Separate toRoute function (#6766)

Because Typescript output is turned to commonjs for these modules currently it’s better to do this. Also convert withRouter to typescript, making it smaller.
parent eb28d4cd
......@@ -4,7 +4,10 @@ import { ComponentType } from 'react';
import { parse } from 'url';
import mitt, {MittEmitter} from '../mitt';
import { formatWithValidation, getURL, loadGetInitialProps } from '../utils';
import {toRoute} from './to-route'
function toRoute(path: string): string {
return path.replace(/\/$/, '') || '/'
}
export interface IRouterInterface {
route: string
......
export function toRoute(path: string): string {
return path.replace(/\/$/, '') || '/'
}
......@@ -3,7 +3,6 @@ import { ParsedUrlQuery } from 'querystring'
import React from 'react'
import { renderToString, renderToStaticMarkup } from 'react-dom/server'
import {IRouterInterface} from '../lib/router/router'
import {toRoute} from '../lib/router/to-route'
import mitt, {MittEmitter} from '../lib/mitt';
import { loadGetInitialProps, isResSent } from '../lib/utils'
import Head, { defaultHead } from '../lib/head'
......@@ -36,7 +35,7 @@ class ServerRouter implements IRouterInterface {
static events: MittEmitter = mitt()
constructor(pathname: string, query: any, as: string) {
this.route = toRoute(pathname)
this.route = pathname.replace(/\/$/, '') || '/'
this.pathname = pathname
this.query = query
this.asPath = as
......
import React, { Component } from 'react'
import React from 'react'
import PropTypes from 'prop-types'
export default function withRouter (ComposedComponent) {
class WithRouteWrapper extends Component {
export default function withRouter(ComposedComponent: React.ComponentType<any> & {getInitialProps?: any}) {
class WithRouteWrapper extends React.Component {
static getInitialProps?: any
static contextTypes = {
router: PropTypes.object
router: PropTypes.object,
}
render () {
render() {
return <ComposedComponent
router={this.context.router}
{...this.props}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment