Commit ccf60f8a by Wee

style: props of LiveRoute now extends type of Route

parent 1dd6f2aa
import { createMemoryHistory } from 'history'
import * as PropTypes from 'prop-types'
import * as React from 'react'
import * as ReactDOM from 'react-dom'
import * as PropTypes from 'prop-types'
import { MemoryRouter, Route, Router } from 'react-router'
import { createMemoryHistory } from 'history'
import { MemoryRouter, Router } from 'react-router'
import Route from '../src/index'
describe('A <Route>', () => {
it('renders at the root', () => {
......
......@@ -32,6 +32,7 @@
"@types/jest": "^24.0.9",
"@types/react": "^16.7.18",
"@types/react-dom": "^16.0.11",
"@types/react-router-dom": "^4.3.1",
"jest": "^24.5.0",
"jest-environment-jsdom": "^24.5.0",
"ts-jest": "^24.0.0",
......
......@@ -3,7 +3,7 @@ import * as invariant from 'invariant'
import * as React from 'react'
import * as PropTypes from 'prop-types'
import * as ReactDOM from 'react-dom'
import { matchPath } from 'react-router'
import { matchPath, Route, RouteProps } from 'react-router'
import { isValidElementType } from 'react-is'
const isEmptyChildren = children => React.Children.count(children) === 0
......@@ -17,15 +17,7 @@ enum LiveState {
type CacheDom = HTMLElement | null
interface IProps {
computedMatch: any // private, from <Switch>
path: string
exact?: boolean
strict?: boolean
sensitive?: boolean
component?: PropTypes.ReactComponentLike
render?: React.StatelessComponent
location: string
interface IProps extends RouteProps {
livePath?: string
alwaysLive: boolean
onHide?: Function
......@@ -332,13 +324,13 @@ class LiveRoute extends React.Component<IProps, any> {
render() {
const { match } = this.state
const { children, component, render, livePath, alwaysLive, onHide } = this.props
const { children, component, render: propRender, livePath, alwaysLive, onHide } = this.props
const { history, route, staticContext } = this.context.router
const location = this.props.location || route.location
const props = { match, location, history, staticContext }
// only affect LiveRoute
if ((livePath || alwaysLive) && (component || render)) {
if ((livePath || alwaysLive) && (component || propRender)) {
debugLog('=== RENDER FLAG: ' + this.liveState + ' ===')
if (
this.liveState === LiveState.NORMAL_RENDER_MATCHED ||
......@@ -346,22 +338,22 @@ class LiveRoute extends React.Component<IProps, any> {
this.liveState === LiveState.NORMAL_RENDER_ON_INIT
) {
// normal render
return this.renderRoute(component, render, props, match)
return this.renderRoute(component, propRender, props, match)
} else if (this.liveState === LiveState.HIDE_RENDER) {
// hide render
const prevRouter = this._latestMatchedRouter
const { history, route, staticContext } = prevRouter // load properties from prevRouter and fake props of latest normal render
const liveProps = { match, location, history, staticContext }
return this.renderRoute(component, render, liveProps, true)
return this.renderRoute(component, propRender, liveProps, true)
}
}
// the following is the same as Route of react-router, just render it normally
if (component) return match ? React.createElement(component, props) : null
if (render) return match ? render(props as any) : null
if (propRender) return match ? propRender(props as any) : null
if (typeof children === 'function') return children(props)
if (typeof children === 'function') return (children as any)(props)
if (children && !isEmptyChildren(children)) return React.Children.only(children)
......
......@@ -309,6 +309,11 @@
dependencies:
"@babel/types" "^7.3.0"
"@types/history@*":
version "4.7.2"
resolved "http://registry.npm.taobao.org/@types/history/download/@types/history-4.7.2.tgz#0e670ea254d559241b6eeb3894f8754991e73220"
integrity sha1-DmcOolTVWSQbbus4lPh1SZHnMiA=
"@types/istanbul-lib-coverage@^1.1.0":
version "1.1.0"
resolved "http://registry.npm.taobao.org/@types/istanbul-lib-coverage/download/@types/istanbul-lib-coverage-1.1.0.tgz#2cc2ca41051498382b43157c8227fea60363f94a"
......@@ -343,6 +348,23 @@
dependencies:
"@types/react" "*"
"@types/react-router-dom@^4.3.1":
version "4.3.1"
resolved "http://registry.npm.taobao.org/@types/react-router-dom/download/@types/react-router-dom-4.3.1.tgz#71fe2918f8f60474a891520def40a63997dafe04"
integrity sha1-cf4pGPj2BHSokVIN70CmOZfa/gQ=
dependencies:
"@types/history" "*"
"@types/react" "*"
"@types/react-router" "*"
"@types/react-router@*":
version "4.4.5"
resolved "http://registry.npm.taobao.org/@types/react-router/download/@types/react-router-4.4.5.tgz#1166997dc7eef2917b5ebce890ebecb32ee5c1b3"
integrity sha1-EWaZfcfu8pF7XrzokOvssy7lwbM=
dependencies:
"@types/history" "*"
"@types/react" "*"
"@types/react@*", "@types/react@^16.7.18":
version "16.7.18"
resolved "http://registry.npm.taobao.org/@types/react/download/@types/react-16.7.18.tgz#f4ce0d539a893dd61e36cd11ae3a5e54f5a48337"
......
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