How to use the next/router.onRouteChangeStart 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 stanleyfok / nextjs-template / components / layout / Layout.js View on Github external
import React from 'react';
import PropTypes from 'prop-types';
import Router from 'next/router';
import Head from 'next/head';
import NProgress from 'nprogress';

// for hot reload purpose
// also allow webpack to extract it
import 'assets/styles/main.scss';
import favIcon from 'assets/images/favicon.png';

import Header from './Header';
import Footer from './Footer';

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

const Layout = props => (
  <div>
    
      
    
    <header>
    <div>{props.children}</div>
    <footer>
  </footer></header></div>
);
github coderplex / linklet-app / hocs / ContainerPage.js View on Github external
import React from 'react'
import Router from 'next/router'
import NProgress from 'nprogress'
import SnackBar from '../components/Snackbar'
import { initGA, logEvent, logPageView } from '../lib/analytics'

Router.onRouteChangeStart = () => {
  console.log('started listening')
  NProgress.start()
}
Router.onRouteChangeComplete = url => {
  logEvent('Navigation', `Navigated to ${url}`)
  NProgress.done()
}
Router.onRouteChangeError = () => {
  NProgress.done()
}

export default Page => {
  return class ContainerPage extends React.Component {
    static async getInitialProps (ctx) {
      try {
        let initialProps = {}
github RelistenNet / relisten-web / pages / index.js View on Github external
if (tape) {
      tape.sets.map(set =>
        set.tracks.map(track => {
          if (track.slug === songSlug) {
            activeTrack = track;
          }
        })
      );
    }
  }

  return { app, playback, url: req ? req.url : null, isMobile, artists, serverRenderedMP3: activeTrack ? activeTrack.mp3_url : null, serverRenderedSongTitle: activeTrack ? activeTrack.title : null };
};

Router.onRouteChangeStart = async (url) => {
  if (typeof window !== 'undefined' && window.UPDATED_TRACK_VIA_GAPLESS) {
    window.UPDATED_TRACK_VIA_GAPLESS = false;
    return 'nonsense';
  }
  const [nextDispatches = [], afterDispatches = []] = handleRouteChange(window.store, url);

  await Promise.all(nextDispatches);
  await Promise.all(afterDispatches.map(f => f()));
};

if (typeof window !== 'undefined') {
  setTimeout(async () => {
    const { currentTime, duration } = localStorage;
    const cachedUrl = window.location.pathname + window.location.search;
    const [artistSlug, ,,, songSlug] = window.location.pathname.replace(/^\//, '').split('/');
github sergiodxa / react-wordpress / components / Page.js View on Github external
import React, { Children } from 'react';
import Head from 'next/head';
import NProgress from 'nprogress';
import Router from 'next/router';


Router.onRouteChangeStart = (url) =&gt; {
  console.log(`Loading: ${url}`);
  NProgress.start();
};
Router.onRouteChangeComplete = () =&gt; NProgress.done();
Router.onRouteChangeError = () =&gt; NProgress.done();


function Page(props) {
  return (
    <section>
      
        <title>
          {props.name} - {props.title}
        </title>
        
        </section>
github opencollective / backyourstack / src / pages / _app.js View on Github external
import App from 'next/app';
import Head from 'next/head';
import React, { Fragment } from 'react';
import Router from 'next/router';
import NProgress from 'nprogress';
import { get } from 'lodash';

import '../static/fonts/inter-ui/inter-ui.css';
import '../static/css/main.css';
import '../static/css/nprogress.css';

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

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

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

class MyApp extends App {
  static async getInitialProps({ Component, ctx }) {
    const { asPath, req, res } = ctx;

    let pageProps = {};

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

    pageProps.pathname = asPath;
github hshoff / vx / packages / vx-demo / components / meta.js View on Github external
import React from 'react';
import Head from 'next/head';
import Router from 'next/router';
import NProgress from 'nprogress';
import ReactGA from 'react-ga';

if (typeof window !== 'undefined' &amp;&amp; window.location.hostname !== 'localhost') {
  ReactGA.initialize('UA-96843800-1');
  ReactGA.set({ page: window.location.pathname });
  ReactGA.pageview(window.location.pathname);
}

Router.onRouteChangeStart = () =&gt; NProgress.start();
Router.onRouteChangeComplete = () =&gt; {
  NProgress.done();
  if (typeof window !== 'undefined' &amp;&amp; window.location.hostname !== 'localhost') {
    ReactGA.set({ page: window.location.pathname });
    ReactGA.pageview(window.location.pathname);
  }
};
Router.onRouteChangeError = () =&gt; NProgress.done();

export default ({ title = 'visualization components' }) =&gt; (
  <div>
    
      
      
      
      </div>
github OrangeXC / gank / components / mobile / Layout.js View on Github external
import Head from 'next/head'
import Router from 'next/router'
import NProgress from 'nprogress'
import { LocaleProvider } from 'antd-mobile'
import enUS from 'antd-mobile/lib/locale-provider/en_US'
import 'isomorphic-fetch'
import pkg from '../../package.json'

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

export default ({ children }) =&gt; (
  <div>
    
      
      <title>Gank</title>
      
      
      
      
    
    
      {children}
    </div>
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 = () =&gt; {
  NProgress.start();
};
Router.onRouteChangeComplete = () =&gt; NProgress.done();
Router.onRouteChangeError = () =&gt; NProgress.done();

function Header() {
  return (
    <div>
      
        
          
            
              <a>
                </a></div>
github ooni / orchestra / frontend / components / meta.js View on Github external
import Head from 'next/head'
import NProgress from 'nprogress'
import Router from 'next/router'

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

export default () =&gt; (
  <div>
		
			
			
			
			
		
		<style>{`
			* {
				margin: 0;
				padding: 0;
				text-rendering: geometricPrecision;</style></div>
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 });
  }