1. // layout.js
    2. import Link from 'next/link'
    3. import Head from 'next/head'
    4. export default ({ children, title = 'This is the default title' }) => ( //解构title和children
    5. <div>
    6. <Head>
    7. <title>{title}</title>
    8. <meta charSet='utf-8' />
    9. <meta name='viewport' content='initial-scale=1.0, width=device-width' />
    10. </Head>
    11. <header>
    12. <nav>
    13. <Link href='/'><a>Home</a></Link> |
    14. <Link href='/about'><a>About</a></Link> |
    15. <Link href='/contact'><a>Contact</a></Link>
    16. </nav>
    17. <p>---------------------------------------</p>
    18. </header>
    19. {children}
    20. <footer>
    21. <p>--------------------------------------</p>
    22. i'm footer
    23. </footer>
    24. </div>
    25. )
    1. // index.js
    2. import react, { Component } from 'react'
    3. import Layout from '../layout/layout'
    4. export default class Index extends Component {
    5. render() {
    6. return (
    7. <Layout title='index'> //通过title设置网页的title
    8. body
    9. </Layout>
    10. )
    11. }
    12. }

    image.png