made with  ♥  by 
React Routing

Routing and navigation solution
for JavaScript applications

10 watchers 321 stars 32 forks 20 open issues

Get Started GitHub View on GitHub
2016-10-20   |   v2.0.0   |   Join #universal-router chat room on Gitter to stay up to date

Universal Router

A simple middleware-style router that can be used in both client-side (e.g. React, Vue.js) and server-side applications (e.g. Node.js/Express, Koa).

Why use Universal Router?

How does it look like?

import { resolve } from 'universal-router';

const routes = [
  {
    path: '/',
    action: () => `<h1>Home</h1>`
  },
  {
    path: '/posts',
    action: () => console.log('checking child routes for /posts'),
    children: [
      {
        path: '/',
        action: () => `<h1>Posts</h1>`
      },
      {
        path: '/:id',
        action: (context) => `<h1>Post #${context.params.id}`
      }
    ]
  },
];

resolve(routes, '/posts').then(html => {
  document.body.innerHTML = html;
});

Note: If you're using the router with Node v5 and below, import it as follows:

import { resolve } from 'universal-router/legacy';

Learn more

Backers

♥ Universal Router? Help us keep it alive by donating funds to cover project expenses!

Konstantin Tarkus Become a backer