Director Router

1.2.8 · abandoned · verified Sun Apr 19

This library, Director Router, provides a routing solution for both client-side (browser) and server-side (Node.js HTTP and CLI) JavaScript applications. It is dependency-free, aiming for minimal differences in usage across environments. Key features include hash-based client-side routing, and traditional path-based routing for Node.js servers and command-line interfaces. The package's current stable version is 1.2.8, released nearly a decade ago. It primarily focuses on hash-based routing for the browser and traditional URL path matching for servers, predating widespread adoption of the HTML5 History API for client-side routing. Its release cadence is effectively stalled, with no updates in many years, making it unsuitable for new projects due to a lack of maintenance and modern feature support.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic client-side hash-based routing in an HTML file using Director, logging route events to the console.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Director Client-Side Routing Example</title>
    <script src="https://rawgit.com/flatiron/director/master/build/director.min.js"></script>
    <script>
      var author = function () { console.log("Route: author"); };
      var books = function () { console.log("Route: books"); };
      var viewBook = function (bookId) {
        console.log("Route: viewBook, ID: " + bookId);
      };

      var routes = {
        '/author': author,
        '/books': [books, function() {
          console.log("Route: An inline handler for books.");
        }],
        '/books/view/:bookId': viewBook
      };

      var router = Router(routes);
      router.init();

      console.log('Router initialized. Click links to test hash-based routing.');
    </script>
  </head>
  <body>
    <h1>Director Client-Side Router</h1>
    <ul>
      <li><a href="#/author">#/author</a></li>
      <li><a href="#/books">#/books</a></li>
      <li><a href="#/books/view/123">#/books/view/123</a></li>
      <li><a href="#/books/view/456">#/books/view/456</a></li>
    </ul>
    <p>Check the console for route handler output.</p>
  </body>
</html>

view raw JSON →