Skip to content

Commit

Permalink
update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
samueljoos committed Feb 11, 2019
1 parent ca2a41e commit 8097bc0
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Create a routes.js file inside your project

```js
// ./routes.js
const router = require('next-avenues');
const { router } = require('next-avenues');

router.add('/', 'index').as('homepage');
router.add('/blog-item/:slug', 'blog').as('blog-item');
Expand Down Expand Up @@ -108,25 +108,31 @@ Most of the times you'll want an **_app.js** component which does the call to yo
import React from 'react';
import App, { Container } from 'next/app';
import routes from '../routes';
export default class App extends React.Component {
static async getInitialProps() {

export default class MyApp extends App {
static async getInitialProps({ Component, ctx }) {
let pageProps = {};
// Retrieve the current route data
// Get current route info.
const route = routes.getCurrentRoute();

if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx, route);
}
}

return { pageProps, route };
}

render() {
const { Component, pageProps, route } = this.props;

return (
<Container>
<Component {...pageProps} route={route}/>
<Component {...pageProps} route={ route }/>
</Container>
);
}
}

```

Now you can access the route data in every page component like this:
Expand Down

0 comments on commit 8097bc0

Please sign in to comment.