diff options
| author | Wes Bos <wesbos@gmail.com> | 2018-05-11 14:53:28 -0400 |
|---|---|---|
| committer | Wes Bos <wesbos@gmail.com> | 2018-05-11 14:53:28 -0400 |
| commit | 4b46d1369b5ea43acd89e2e274c04a6f6e214e2c (patch) | |
| tree | 9e03deee7a754ac9bc3e4920a09fe620836b8b13 /frontend/pages | |
| parent | d88e20901e8fca1ff94a1f80f7a9e0ac3481c8e8 (diff) | |
app
Diffstat (limited to 'frontend/pages')
| -rw-r--r-- | frontend/pages/_app.js | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/frontend/pages/_app.js b/frontend/pages/_app.js index daa3e68..c741c4d 100644 --- a/frontend/pages/_app.js +++ b/frontend/pages/_app.js @@ -1,30 +1,32 @@ import App, { Container } from 'next/app'; import React from 'react'; import withData from '../lib/withData'; +import { withRouter } from 'next/router'; // Next.js wraps each Page in an <App></App> component. This is handy for when you want to persist anything from page to page, or just access a component that is 1 level higher than each page. // This code is taken right from the Next.js docs, and then we add the Router to the page props, which is why we need a custom _app.js +let ComposedComponent; + class MyApp extends App { static async getInitialProps({ Component, router, ctx }) { let pageProps = {}; + ComposedComponent = withData(Component); - if (Component.getInitialProps) { - pageProps = await Component.getInitialProps(ctx); + if (ComposedComponent.getInitialProps) { + pageProps = await ComposedComponent.getInitialProps(ctx); } - // surface the router on each page pageProps.router = router; - - console.log(router.query); return { pageProps }; } render() { const { Component, pageProps } = this.props; + return ( <Container> - <Component {...pageProps} /> + <ComposedComponent {...pageProps} /> </Container> ); } |
