-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c383307
commit 3bbd0c8
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from "react"; | ||
import App, { Container } from "next/app"; | ||
|
||
export default class MyApp extends App { | ||
static async getInitialProps({ Component, ctx }) { | ||
let pageProps = {}; | ||
|
||
if (Component.getInitialProps) { | ||
pageProps = await Component.getInitialProps(ctx); | ||
} | ||
|
||
return { pageProps }; | ||
} | ||
|
||
createUrl = router => { | ||
// This is to make sure we don't references the router object at call time | ||
const { pathname, asPath, query } = router; | ||
return { | ||
get query() { | ||
return query; | ||
}, | ||
get pathname() { | ||
return pathname; | ||
}, | ||
get asPath() { | ||
return asPath; | ||
}, | ||
back: () => { | ||
router.back(); | ||
}, | ||
push: (url, as) => router.push(url, as), | ||
pushTo: (href, as) => { | ||
const pushRoute = as ? href : null; | ||
const pushUrl = as || href; | ||
|
||
return router.push(pushRoute, pushUrl); | ||
}, | ||
replace: (url, as) => router.replace(url, as), | ||
replaceTo: (href, as) => { | ||
const replaceRoute = as ? href : null; | ||
const replaceUrl = as || href; | ||
|
||
return router.replace(replaceRoute, replaceUrl); | ||
} | ||
}; | ||
}; | ||
|
||
render() { | ||
const { Component, pageProps, router } = this.props; | ||
const url = this.createUrl(router); | ||
return ( | ||
<Container> | ||
<Component {...pageProps} url={url} /> | ||
</Container> | ||
); | ||
} | ||
} |