Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Express无法正确路由HTML_Javascript_Node.js_Express - Fatal编程技术网

Javascript Express无法正确路由HTML

Javascript 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文件。在这种情况下,默认路由是/ 尝试将此添加

我正在用Express创建一个网站。我的主要问题是找不到将导航栏选项卡链接在一起的方法

index.html

例如,问题是当用户登录index.html并希望访问OurPool.html时。这将获取以下错误消息:

404未找到nginx/1.18.0 Ubuntu


您需要为该端点添加适当的路由,就像对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')});

})