import React from 'react' ; import { Link } from 'react-router-dom' ; import './index.less' ; interface Props { news : NewsItem [ ] ; } interface NewsItem { id : string ; title : string ; } const Page = ( props ) : JSX . Element => { return ( < div className = 'normal' > < div className = 'welcome' / > < ul className = 'list' > { props . news && props . news . map ( ( item ) => ( < li key = { item . id } > < div > 文章标题 : { item . title } < /div> < div className = 'toDetail' > < Link to = { `/news/${ item . id }` } > 点击查看详情 < /Link></div > < /li>))} < /ul> < /div>); } ; Page . getInitialProps = async ( ctx ) => { return __isBrowser__ ? ( await window . fetch ( '/api/getIndexData' ) ) . json ( ) : ctx . apiService ( ) ; } ; export default Page ;