外部 css 和 js 没有在内页中加载 nodejs express
external css and js not loading in inner pages nodejs express
我正在使用 nodejs
创建博客应用程序并使用 ejs
表达。使用单个 URL
(表示 http://localhost/ 或 http://localhost/anything )一切正常,但是当我尝试访问此页面外部页面中的页面 http://localhost/blog/create
时 stylesheet
或 javascript
不工作,加载为 http://localhost/blog/css/style.css
(应该是 http://localhost/css/style.css)
.
我正在使用静态中间件从 public 目录
加载 css
和 js
app.use(express.static(__dirname + '/public'));
页眉和页脚正在使用 <%- include('./partials/header') %>
加载
目录结构:
View Files : views
header & footer : views/Partials
css and js : public
您的风格 sheet 应该使用 '/css/style.css'
而不是 'css/style.css'
这里有一些很好的解释
Absolute vs relative URLs
我正在使用 nodejs
创建博客应用程序并使用 ejs
表达。使用单个 URL
(表示 http://localhost/ 或 http://localhost/anything )一切正常,但是当我尝试访问此页面外部页面中的页面 http://localhost/blog/create
时 stylesheet
或 javascript
不工作,加载为 http://localhost/blog/css/style.css
(应该是 http://localhost/css/style.css)
.
我正在使用静态中间件从 public 目录
加载css
和 js
app.use(express.static(__dirname + '/public'));
页眉和页脚正在使用 <%- include('./partials/header') %>
目录结构:
View Files : views
header & footer : views/Partials
css and js : public
您的风格 sheet 应该使用 '/css/style.css'
而不是 'css/style.css'
这里有一些很好的解释 Absolute vs relative URLs