import App, { Container } from "next/app"; import React from "react"; import Head from "next/head"; import Router, { withRouter } from "next/router"; import Layout from "../components/Layout"; import NProgress from "nprogress"; import { routes, activeRouteData } from "../utils/routes"; NProgress.configure({ showSpinner: false }); Router.onRouteChangeStart = url => { if (url.indexOf("code=") === -1) { NProgress.start(); } }; Router.onRouteChangeComplete = () => NProgress.done(); Router.onRouteChangeError = () => NProgress.done(); class MyApp extends App { static async getInitialProps({ Component, router, ctx }) { let pageProps = {}; if (Component.getInitialProps) { pageProps = await Component.getInitialProps(ctx); } return { pageProps }; } componentDidMount() { routes.forEach(({ path }) => Router.prefetch(path)); } render() { const { Component, pageProps, router } = this.props; const { label, desc, title } = activeRouteData(router.pathname) || {}; return ( {title || label} ); } } export default withRouter(MyApp);