JavaScript的URL路由:Director(Director.js)
Director(Director.js) 是个路由,当一个 URL 请求的时候可以决定代码在哪里运行。
Features
- Client-Side Routing
- Server-Side HTTP Routing
- Server-Side CLI Routing
简单示例
<!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>
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!