Skip to content

Commit

Permalink
bugfix url property is depricated
Browse files Browse the repository at this point in the history
  • Loading branch information
aminkhademian committed Jun 22, 2018
1 parent c383307 commit 3bbd0c8
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions pages/_app.js
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>
);
}
}

0 comments on commit 3bbd0c8

Please sign in to comment.