Skip to content
A simple middleware-style router for isomorphic JavaScript web apps
Branch: master
Clone or download
Latest commit 0c664b9 Feb 20, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Update dependencies Aug 20, 2018
dist Add synchronous mode as an add-on (#164) Feb 20, 2019
docs Add synchronous mode as an add-on (#164) Feb 20, 2019
src Add synchronous mode as an add-on (#164) Feb 20, 2019
test Add synchronous mode as an add-on (#164) Feb 20, 2019
tools Add synchronous mode as an add-on (#164) Feb 20, 2019
.babelrc Update Babel and reduce library size Jan 28, 2018
.editorconfig Update Router API (#83) Mar 25, 2017
.eslintrc Update dependencies Aug 20, 2018
.gitattributes Update dev dependencies Apr 6, 2018
.gitignore Replace mocha, chai and sinon with jest (#151) Mar 7, 2018
.huskyrc Update dev dependencies Oct 5, 2018
.travis.yml Update dependencies Aug 20, 2018 8.1.0 Feb 20, 2019
LICENSE.txt Update Babel and reduce library size Jan 28, 2018 Update dependencies Aug 20, 2018
logo.svg Add logo Jan 28, 2018
package.json 8.1.0 Feb 20, 2019
tsconfig.json Add TypeScript typings (#159) Jan 15, 2019

Universal Router

NPM version NPM downloads Library Size Online Chat

Visit Universal Router Website

A simple middleware-style router that can be used in both client-side and server-side applications.

Visit Quickstart Guide (slides)  |  Join #universal-router on Gitter to stay up to date


What users say about Universal Router

Just switched a project over to universal-router. Love that the whole thing is a few hundred lines of flexible, easy-to-read code.

-- Tweet by Greg Hurrell from Facebook

It does a great job at trying to be universal — it's not tied to any framework, it can be run on both server and client, and it's not even tied to history. It's a great library which does one thing: routing.

-- Comment on Reddit by @everdimension


Using npm:

npm install universal-router --save

Or using a CDN like or jsDelivr with the following script tag:

<script src=""></script>

You can find the library in window.UniversalRouter.

How does it look like?

import UniversalRouter from 'universal-router'

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

const router = new UniversalRouter(routes)

router.resolve('/posts').then(html => {
  document.body.innerHTML = html // renders: <h1>Posts</h1>

Play with an example on JSFiddle, CodePen, JS Bin in your browser or try RunKit node.js playground.


Books and Tutorials

Browser Support

We support all ES5-compliant browsers, including Internet Explorer 9 and above, but depending on your target browsers you may need to include polyfills for Map, Promise and Object.assign before any other code.

For compatibility with older browsers you may also need to include polyfills for Array.isArray and Object.create.


Anyone and everyone is welcome to contribute to this project. The best way to start is by checking our open issues, submit a bug report or feature request, participate in discussions, upvote or downvote the issues you like or dislike, send pull requests.


Related Projects

  • React Starter Kit — Boilerplate and tooling for building isomorphic web apps with React and Relay.
  • Node.js API Starter Kit — Boilerplate and tooling for building data APIs with Docker, Node.js and GraphQL.
  • ASP.NET Core Starter Kit — Cross-platform single-page application boilerplate (ASP.NET Core, React, Redux).
  • Babel Starter Kit — Boilerplate for authoring JavaScript/React.js libraries.
  • React App SDK — Create React apps with just a single dev dependency and zero configuration.
  • React Static Boilerplate — Single-page application (SPA) starter kit (React, Redux, Webpack, Firebase).
  • History — HTML5 History API wrapper library that handle navigation in single-page apps.
  • Redux-First Routing — A minimal, framework-agnostic API for accomplishing Redux-first routing.


Become a sponsor and get your logo on our README on Github with a link to your site. [Become a sponsor]


Support us with a monthly donation and help us continue our activities. [Become a backer]


Copyright © 2015-present Kriasoft. This source code is licensed under the MIT license found in the LICENSE.txt file. The documentation to the project is licensed under the CC BY-SA 4.0 license.

Made with ♥ by Konstantin Tarkus (@koistya, blog), Vladimir Kutepov and contributors

You can’t perform that action at this time.