我正在使用react-engine
为服务器提供访问反应组件的权限。使用react-engine
,您可以通过路由url并使用res.render来提供express
反应。为此,您需要提供文档指定的路径req.url
。React引擎导致“找不到模块”错误
app.use("/", function(req, res){
return res.render(req.url, data);
})
现在,当URL是/index
将被传递到react-router
和作出反应,在该端点返回的路线会被编译成一个字符串。
我遇到的问题是当URL有一段时间。
每当get查询(/index.html
)或路径路径本身(/index?example=foo.bar
)中存在句点时,出现错误提示以下内容。
Cannot find module 'html'
或
Cannot find module 'bar'
分别。
我是否必须将期间转移到网址?
res.render(req.url.replace(/\./g, ""), data)
我该如何摆脱Cannot find module 'extension'
消息?
我也把a specific issue here在react-engine
在github上。
我挖掘到这一点,我想可能有一些两者并与德快递视图引擎[点击这里] (https://github.com/paypal/react-engine/blob/master/lib/expressView.js#L23)。当任何路由包含一段时间时发生错误:http://stackoverflow.com/questions/16111386/node-js-cannot-find-module-html – ThomasReggi
我认为它的发生是因为'express/lib/view'认为文件被传递的是一个普通的视图模板,比如'index.jade',它的功能是解析扩展以找到它使用的模板库。https://github.com/strongloop/express/blob/master/lib/view.js #L76-L79 – ThomasReggi