How to use the next/router.onRouteChangeComplete function in next

To help you get started, we’ve selected a few next examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github styled-components / styled-components-website / utils / track.js View on Github external
const reportView = () => {
    const { pathname } = window.location;

    fetch('https://sc-micro-analytics.now.sh' + pathname)
      .then(() => {
        console.log(`Reported page view for ${pathname}.`);
      })
      .catch(err => {
        console.warn('Could not report page view:', err);
      });
  };

  reportView();

  Router.onRouteChangeComplete = () => {
    reportView();
  };
}
github mui-org / material-ui / docs / src / modules / components / AppFrame.js View on Github external
import AppDrawer from 'docs/src/modules/components/AppDrawer';
import Notifications from 'docs/src/modules/components/Notifications';
import MarkdownLinks from 'docs/src/modules/components/MarkdownLinks';
import usePageTitle from 'docs/src/modules/components/usePageTitle';
import { LANGUAGES_LABEL } from 'docs/src/modules/constants';
import { pathnameToLanguage } from 'docs/src/modules/utils/helpers';
import { useChangeTheme } from 'docs/src/modules/components/ThemeContext';

const LOCALES = { zh: 'zh-CN', pt: 'pt-BR', es: 'es-ES' };
const CROWDIN_ROOT_URL = 'https://translate.material-ui.com/project/material-ui-docs/';

Router.onRouteChangeStart = () => {
  NProgress.start();
};

Router.onRouteChangeComplete = () => {
  NProgress.done();
};

Router.onRouteChangeError = () => {
  NProgress.done();
};

const AppSearch = React.lazy(() => import('docs/src/modules/components/AppSearch'));
function DeferredAppSearch() {
  const fallback = null;

  const [mounted, setMounted] = React.useState(false);
  React.useEffect(() => {
    setMounted(true);
  }, []);
github liors / tvdapp / components / navigation.js View on Github external
import Link from 'next/link'
import NProgress from 'nprogress'
import Router from 'next/router'

Router.onRouteChangeStart = url => NProgress.start()
Router.onRouteChangeComplete = () => NProgress.done()
Router.onRouteChangeError = () => NProgress.done()
  
export default ( { selected }) => {
    let {selectionFreshClass, selectionNewClass, selectionPopularClass, selectionBookmarksClass} = 'gray'
    
    switch(selected) {
        case 'fresh':
        selectionFreshClass = 'black b'
            break;
        case 'new':
        selectionNewClass = 'black b'
            break;
        case 'popular':
        selectionPopularClass = 'black b'
            break;
        case 'bookmarks':
github wesbos / Advanced-React / stepped-solutions / 09 / frontend / components / Header.js View on Github external
import Link from 'next/link';
import styled from 'styled-components';
import Router from 'next/router';
import NProgress from 'nprogress';
import Nav from './Nav';

Router.onRouteChangeStart = () => {
  NProgress.start();
};

Router.onRouteChangeComplete = () => {
  NProgress.done();
};

Router.onRouteChangeError = () => {
  NProgress.done();
};

const Logo = styled.h1`
  font-size: 4rem;
  margin-left: 2rem;
  position: relative;
  z-index: 2;
  transform: skew(-7deg);
  a {
    padding: 0.5rem 1rem;
    background: ${props => props.theme.red};
github builderbook / builderbook / book / 5-end / lib / withLayout.js View on Github external
import React from 'react';
import PropTypes from 'prop-types';
import { MuiThemeProvider } from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import Router from 'next/router';
import NProgress from 'nprogress';

import getContext from './context';
import Header from '../components/Header';
import Notifier from '../components/Notifier';

Router.onRouteChangeStart = () => NProgress.start();
Router.onRouteChangeComplete = () => NProgress.done();
Router.onRouteChangeError = () => NProgress.done();

function withLayout(BaseComponent) {
  class App extends React.Component {
    constructor(props) {
      super(props);
      const { pageContext } = this.props;
      this.pageContext = pageContext || getContext();
    }

    componentDidMount() {
      const jssStyles = document.querySelector('#jss-server-side');
      if (jssStyles && jssStyles.parentNode) {
        jssStyles.parentNode.removeChild(jssStyles);
      }
    }
github builderbook / builderbook / tutorials / 1-start / components / Header.js View on Github external
import Link from 'next/link';
import Router from 'next/router';
import NProgress from 'nprogress';
import Toolbar from 'material-ui/Toolbar';
import Grid from 'material-ui/Grid';
import Avatar from 'material-ui/Avatar';

import { styleToolbar } from './SharedStyles';

Router.onRouteChangeStart = () => {
  NProgress.start();
};
Router.onRouteChangeComplete = () => NProgress.done();
Router.onRouteChangeError = () => NProgress.done();

function Header() {
  return (
    <div>
      
        
          
            
              <a>
                
              </a></div>
github codeleakteam / codeleak / nextjs / pages / _app.js View on Github external
componentDidMount() {
    if (!localStorage.getItem('codeleak-cookies')) {
      GdprNotification()
    }

    Router.onRouteChangeComplete = url => {
      trackPageView(url)
    }
  }
github RafalWilinski / lobby / components / DashboardWrapper.js View on Github external
componentDidMount() {
    Router.onRouteChangeStart = url => {
      this.setState({
        isLoading: true
      });
    };

    Router.onRouteChangeComplete = () => this.setState({ isLoading: false });
    Router.onRouteChangeError = () => this.setState({ isLoading: false });
  }
github dpla / dpla-frontend / pages / exhibitions / exhibition / section / subsection.js View on Github external
componentDidMount() {
    this.trackPageview();
    Router.onRouteChangeComplete = url => this.trackPageview();
  }
github hubidu / heimdall-io / report-app / components / layout.js View on Github external
import Link from 'next/link'
import Head from 'next/head'

import NProgress from 'nprogress'
import Router from 'next/router'

Router.onRouteChangeStart = (url) => {
  NProgress.start()
}
Router.onRouteChangeComplete = () => NProgress.done()
Router.onRouteChangeError = () => NProgress.done()

const linkToProjects = ownerkey => {
  return {
    pathname: '/projects',
    query: { ownerkey }
  }
}
const linkToTestStatus = ownerkey => {
  return {
    pathname: '/test-status',
    query: { ownerkey }
  }
}

export default ({ children, title = '', ownerkey, showNav = true }) => (