JavaScript的URL路由:Director(Director.js)

jopen 5年前

Director(Director.js) 是个路由,当一个 URL 请求的时候可以决定代码在哪里运行。

Features

  • Client-Side Routing
  • Server-Side HTTP Routing
  • Server-Side CLI Routing

JavaScript的URL路由:Director(Director.js)

简单示例

<!DOCTYPE html>  <html>    <head>      <meta charset="utf-8">      <title>A Gentle Introduction</title>      <script        src="https://rawgit.com/flatiron/director/master/build/director.min.js">      </script>      <script>        var author = function () { console.log("author"); };        var books = function () { console.log("books"); };        var viewBook = function (bookId) {          console.log("viewBook: bookId is populated: " + bookId);        };        var routes = {          '/author': author,          '/books': [books, function() {            console.log("An inline route handler.");          }],          '/books/view/:bookId': viewBook        };        var router = Router(routes);        router.init();      </script>    </head>    <body>      <ul>        <li><a href="#/author">#/author</a></li>        <li><a href="#/books">#/books</a></li>        <li><a href="#/books/view/1">#/books/view/1</a></li>      </ul>    </body>  </html>

项目主页:http://www.open-open.com/lib/view/home/1435309264607