{"size": 789, "ext": "js", "max_stars_repo_path": "37.react/router2/react-router-dom/Switch.js", "max_stars_repo_name": "sillyhong/whongjiagou-learn", "max_stars_repo_stars_event_min_datetime": "2020-06-15T03:26:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-28T07:40:54.000Z", "max_issues_repo_path": "37.react/router2/react-router-dom/Switch.js", "max_issues_repo_name": "sillyhong/whongjiagou-learn", "max_issues_repo_issues_event_min_datetime": "2021-03-09T20:56:53.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-12T23:08:10.000Z", "max_forks_repo_path": "37.react/router2/react-router-dom/Switch.js", "max_forks_repo_name": "sillyhong/whongjiagou-learn", "max_forks_repo_forks_event_min_datetime": "2021-11-28T10:13:24.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-28T10:13:24.000Z"}
{"max_stars_count": 5, "max_issues_count": 6, "max_forks_count": 1, "avg_line_length": 32.875, "max_line_length": 60, "alphanum_fraction": 0.5779467681}
import React, { Component } from 'react'
import { HashContext } from '../context/HashContext'
import pathToRegExp from 'path-to-regexp'
export default class Switch extends Component {
    static contextType = HashContext
    render() {
        const { pathname } = this.context.location
        const  childrens = this.props.children
        console.log('switch', this.props)
        for(let i = 0; i < childrens.length; i++) {
            let child = childrens[i]
            let { path, exact=false } = child.props
            let reg = pathToRegExp(path, [], { end: exact })
            let result = pathname.match(reg)
        console.log('pathname', pathname, 'result', result)

            if(result){
                return child
            }
        }
        return null
    }
}
