import React from 'react' ; import { Route , Switch , Redirect } from 'react-router-dom' ; import AsyncComponent from '@app/components/async-component' ; import routerList from './list' ; interface Params { user ? : object ; enterEvent ? : ( s ? : any ) => void ; } type Result = { list : Array < object > ; dom : object ; } ; export default ( { user , enterEvent = ( ) => { } } ) : Result => { const enter = ( role , Layout , props , route ) => { enterEvent ( ) ; switch ( role ) { case 'everybody' : return < Layout { ... props } / > ; case 'tourists' : if ( user ) { return < Redirect to = "/" / > ; } else { return < Layout { ... props } / > ; } case 'member' : if ( ! user ) { return < Redirect to = "/" / > ; } else { return < Layout { ... props } / > ; } } } ; let dom = ( props ) => ( < div > { } < Switch > { routerList . map ( ( route , index ) => ( < Route key = { index } path = { route . path } exact = { route . exact } component = { route . head } / > ) ) } < /Switch> { } < Switch > { routerList . map ( ( route , index ) => { if ( ! route . body ) return ; return ( < Route key = { index } path = { route . path } exact = { route . exact } render = { ( props ) => enter ( route . enter , route . body , props , route ) } />); } ) } < /Switch> { } < AsyncComponent load = { ( ) => import ( '../components/global' ) } > { ( Component ) => < Component />} < /AsyncComponent> < /div>); return { list : routerList , dom } ; } ;