Javascript Express无法正确路由HTML
我正在用Express创建一个网站。我的主要问题是找不到将导航栏选项卡链接在一起的方法 index.html 例如,问题是当用户登录index.html并希望访问OurPool.html时。这将获取以下错误消息: 404未找到nginx/1.18.0 UbuntuJavascript Express无法正确路由HTML,javascript,node.js,express,Javascript,Node.js,Express,我正在用Express创建一个网站。我的主要问题是找不到将导航栏选项卡链接在一起的方法 index.html 例如,问题是当用户登录index.html并希望访问OurPool.html时。这将获取以下错误消息: 404未找到nginx/1.18.0 Ubuntu 您需要为该端点添加适当的路由,就像对index.html所做的那样: 这是因为您没有在app.get方法中处理/ourpool的请求路由。当用户登陆您的站点时,您只发送index.html文件。在这种情况下,默认路由是/ 尝试将此添加
您需要为该端点添加适当的路由,就像对index.html所做的那样:
这是因为您没有在app.get方法中处理/ourpool的请求路由。当用户登陆您的站点时,您只发送index.html文件。在这种情况下,默认路由是/ 尝试将此添加到代码中:
app.get('/ourpool', function(req, res) {
res.sendFile('OurPool.html', {root:path.join(__dirname,'public')});
})
const express = require('express')
const app = express()
var path = require('path')
app.use(express.static('website/public'))
const port = 5555
app.get('/', function(req, res) {
res.sendFile('index.html', {root:path.join(__dirname,'public')});
})
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
app.get('/OurPool.html', function(req, res) {
res.sendFile('OurPool.html', {root:path.join(__dirname,'public')});
});
app.get('/ourpool', function(req, res) {
res.sendFile('OurPool.html', {root:path.join(__dirname,'public')});
})