Skip to content

Instantly share code, notes, and snippets.

@therebelrobot
Created October 26, 2016 22:39
Show Gist options
  • Save therebelrobot/6fdf54d18ef560f9dccb291e2b2ba895 to your computer and use it in GitHub Desktop.
Save therebelrobot/6fdf54d18ef560f9dccb291e2b2ba895 to your computer and use it in GitHub Desktop.
Why a new Router?

Next.js is special in that:

  • Routes don’t need to be known ahead of time
  • Routes are always lazy-loadable
  • Top-level components can define getInitialProps that should block the loading of the route (either when server-rendering or lazy-loading)

As a result, we were able to introduce a very simple approach to routing that consists of two pieces:

  • Every top level component receives a url object to inspect the url or perform modifications to the history
  • A <Link /> component is used to wrap elements like anchors (<a/>) to perform client-side transitions

We tested the flexibility of the routing with some interesting scenarios. For an example, check out nextgram.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment