javascript Express、Jade 和 NodeJS:在页面之间导航
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28925417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 09:45:59 来源:igfitidea点击:
Express, Jade, & NodeJS: Navigate between pages
提问by janiv
How do I create a Jade page that has two buttons where each one of them redirects to another page made with Jade?
我如何创建一个 Jade 页面,它有两个按钮,每个按钮都重定向到另一个用 Jade 制作的页面?
回答by LucaSpeedStack
This is the code I made for your question:
这是我为您的问题制作的代码:
server.js
服务器.js
var express = require('express');
var path = require('path');
var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.get('/', function(req, res){
res.render('layout', {
title: 'Home'
});
});
app.get('/newpage', function(req, res){
res.render('anotherpage', {
title: 'Home'
});
});
app.listen(3000);
page1.jade
page1.玉
doctype html
html
head
title= title
body
p hi there!
button(onclick="move()") newPage
script.
function move() {
window.location.href = '/newpage'
}
anotherpage.jade
另一页玉
doctype html
html
head
title= title
body
p welcome to the other page!
Enjoy, because it took me 15 minutes to write all this and the post.
享受吧,因为我花了 15 分钟才写完所有这些和帖子。
Luca
卢卡