node.js&express – res.render()重置静态htmlpath

我得到这样的要求:

app.get('/page/:no', article.home); 

用这个发送回应:

 res.render('article', {article: articleContents}); 

那么CSS文件和脚本文件的链接已经改变。像这样:

 GET /bower_components/bootstrap/dist/css/bootstrap.min.css 304 5ms (correct) GET /page/bower_components/bootstrap/dist/css/bootstrap.min.css 404 3ms (wrong, I don't need '/page') 

如何解决它?

您是否正在使用root-edpath加载您的bootstrap.min.css ? 即

 /bower_components/bootstrap/dist/css/bootstrap.min.css 

或者你正在加载一个相对path?

 bower_components/bootstrap/dist/css/bootstrap.min.css 

注意在开始时缺less正斜杠