如何运行nodejs flatiron / director示例

我试图运行https://github.com/flatiron/director#client-side例子来熟悉director.js。

我无法在客户端设置熨斗模块。

在我的html页面(比如<my_project>/page.html )中,我将director.js的位置replace为我项目中对应的位置:

<my_project>/node_modules/flatiron/node_modules/director/lib/director.js

在浏览器中加载<my_project>/page.html页面时出现错误:export和Router未定义。

第一个想法:毕竟,在浏览器端没有nodejs …

好的,我认为browserify可以帮助我。 我生成了一个“浏览器端”包(是否有必要?):

 my_project> node node_modules/browserify/bin/cli.js node_modules/flatiron/node_modules/director/lib director.js -o cs_director.js 

我使用它: <script src="cs_director.js"></script>

问题是这个错误

 Uncaught ReferenceError: Router is not defined (anonymous function) 

仍然出现,所以我猜整个例子将无法正常工作。

我是node / js的新手,我不确定它是否让我感觉到我在上面描述的情况下做了什么…有人如何解决它?

或者一般来说,如何在浏览器端使用“同构”的东西? Github上的html例子只是将相同的.js文件引用为服务器端的例子。

你能推荐任何教程,例子吗?

谢谢,-gvlax

您可以在这里find一个浏览器特定的director版本,其中所有的服务器代码都被剥离了。

谢谢DeadDEnD,

现在它就像一个魅力!

我不知道我怎么能错过自述文件中的信息…我首先阅读手册,我发誓:-)

这是我的示例代码:

  <!html> <html> <head> <script src="director-1.0.7.min.js"></script> <script> var author = function () { console.log("author called.");}, books = function () { console.log("books called."); }, viewBook = function(bookId) { console.log("viewBook called."); }; var routes = { '/author': author, '/books': [books, function() { console.log("anonymous fun called."); }], '/books/view/:bookId': viewBook }; var router = Router(routes); router.init(); </script> </head> <body> Click <a href="#/books">me</a> to call two functions at a time. </body> </html> 

–gvlax