无法通过express.js链接2个HTML页面



我无法链接我的predict.html页面和index.html。每当单击开始按钮时,我不会收到任何错误,但也不会重定向到所需的页面

这是我的代码

index.html

<body>
<!-- The Navbar Section -->
<div>
<ul>
<li class="Mouse" style="padding-left:30px ;"><a href="#" class="heading">Bull-Dozer Price Predictor</a></li>


<li style="float:right"><a href="#">Contact</a></li>
<li style="float:right"><a href="#">Product</a></li>
<li style="float:right"><a href="#">Home</a></li>
</ul>
</div>  

<!-- The Header Section -->
<div style="padding:10%;">
<h1 style="font-size:5em ;">  The Bull-Dozer Price <br> Predictor</h1>
<form method="post">
<button type="button" class="btn btn-warning btn-lg start" style="color: white; width: 150px; font-size: 2em;"> Start</button>
</form>
</div>   

这是app.js文件

app.js

const express = require("express");
const bodyParser = require("body-parser");

const app = express();
app.use(express.static("public"))
app.use(bodyParser.urlencoded({extended: true}))
app.get("/", function(req,res){
res.sendFile(__dirname + "/public/index.html");
})
app.post("/", function(req,res){
res.sendFile(__dirname + "/public/predict.html");
});

app.listen(process.env.PORT || 3000, function(req,res){
console.log("Server running on port 3000")
})

我希望你不要添加一个&quot__目录名+";在快速静态尝试低于代码

const express = require("express");
const bodyParser = require("body-parser");
const app = express();
app.use(express.static(__dirname + "/public"))
app.use(bodyParser.urlencoded({extended: true}))
app.get("/", function(req,res){
res.sendFile(__dirname + "/public/index.html");
});
app.post("/", function(req,res){
res.sendFile(__dirname + "/public/predict.html");
});
app.listen(process.env.PORT || 3000, function(req,res){
console.log("Server running on port 3000");
});

最新更新