问题
I have a layout.hbs file that has a stylesheet linked to it but it doesn't seem like it is connected to the app. I already have express, path and hbs required. I might be accessing it incorrectly but my text editor is able to redirect me to the .css file path regardless. Express is using the static folder public and I tried /public and public. Both don't seem to work.
app.use(express.static(path.join(__dirname, '/public')));
My directory looks something like this
views
-layouts
public
-stylesheets
--layout
My layout hbs file looks like this
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>TITLE</title>
<link rel="stylesheet" href="/public/stylesheets/style.css">
</head>
<body>
<h1>HELLO WORLD</h1>
{{{ body }}}
</body>
</html>
回答1:
Change the below in your code
<link rel="stylesheet" href="/public/stylesheets/style.css">
to
<link rel="stylesheet" href="/stylesheets/style.css">
来源:https://stackoverflow.com/questions/47371954/cannot-access-stylesheet-with-handlebars