File Author Date Description import * as React from 'react' ; import { Switch , Route , Redirect } from 'react-router-dom' ; import * as cx from 'classnames' ; import { components } from './config' ; import SideBar from './SideBar' ; import './base.scss' ; const genCategory = ( key ) => ( { match } ) => ( < Switch > { components [ key ] . map ( item => ( < Route key = { item . path } path = { `${ match . url }/${ item . path }` } component = { item . Component } / > ) ) } < Route render = { ( ) => ( < Redirect to = { `${ match . url }/${ components [ key ] [ 0 ] . path }` } />)}/ > < /Switch>); const Example = ( { match } ) => ( < div className = { cx ( 'demo-example' ) } > < SideBar match = { match } /> < div className = { cx ( 'demo-example-content' ) } > < Switch > { components . categories . map ( ( { path } ) => ( < Route key = { path } path = { `${ match . url }/${ path }` } render = { genCategory ( path ) } / > ) ) } < Route render = { ( ) => ( < Redirect to = { `${ match . url }/${ components . categories [ 0 ] . path }` } />)}/ > < /Switch> < /div> < /div>); export default Example ;