我使用ExpressJs創建了一個簡單的登錄系統,並在提交表單時將用戶定向到www.mywebsite.com/submit並查看「Not Found 404」但是當我刷新同一頁時,我看到了該視圖。404未找到表單提交但在重新加載相同URL時工作
我不知道原因是什麼,但這裏是代碼
Index.js(路線)
var express = require('express');
var router = express.Router();
router.get('/', function(req, res) {
res.render('index', { title: 'Express' });
});
router.get('/submit', function(req, res){
res.render('submit');
});
module.exports = router;
Submit.jade
extends layout
block content
h1 Successfully Logged In
404未找到錯誤
Error: Not Found at Layer.app.use.res.render.message [as handle (/Applications/MAMP/htdocs/nodejs/app.js:29:15)
at trim_prefix (/Applications/MAMP/htdocs/nodejs/node_modules/express/lib/router/index.js:240:15)
at /Applications/MAMP/htdocs/nodejs/node_modules/express/lib/router/index.js:208:9
at Function.proto.process_params (/Applications/MAMP/htdocs/nodejs/node_modules/express/lib/router/index.js:269:12)
at next (/Applications/MAMP/htdocs/nodejs/node_modules/express/lib/router/index.js:199:19)
at next (/Applications/MAMP/htdocs/nodejs/node_modules/express/lib/router/index.js:176:38)
at /Applications/MAMP/htdocs/nodejs/node_modules/express/lib/router/index.js:137:5
at /Applications/MAMP/htdocs/nodejs/node_modules/express/lib/router/index.js:250:10
at next (/Applications/MAMP/htdocs/nodejs/node_modules/express/lib/router/index.js:160:14)
at next_layer (/Applications/MAMP/htdocs/nodejs/node_modules/express/lib/router/route.js:77:14)
您需要通過調用'router.post()定義POST方法的路徑' – nullability