fridays / next-routes

Universal dynamic routes for Next.js
MIT License
2.47k stars 230 forks source link

Problem with router event handlers #112

Closed arefaslani closed 7 years ago

arefaslani commented 7 years ago

By using this router, handlers like onRouteChangeStart will not work.

arefaslani commented 7 years ago

Pardon me, That was just a mistake.

nickyhajal commented 6 years ago

Sorry to bring this up again - but what was your mistake? next/router events aren't firing for me at the moment so perhaps I'm doing the same thing?

Thanks!

arefaslani commented 6 years ago

@nickyhajal Sorry but I don't remember what was my problem. But this is a simple component that uses routes events that may help:

import React from "react";
import Head from "next/head";
import NProgress from "nprogress";
import { Router } from "routes";

NProgress.configure({ showSpinner: false });

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

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

export default () => (
  <div style={{ marginBottom: 20 }}>
    <Head>
      {/* Import CSS for nprogress */}
      <link rel="stylesheet" type="text/css" href="/static/css/nprogress.css" />
    </Head>
  </div>
);