简体   繁体   English

Express,Jade和NodeJS:在页面之间导航

[英]Express, Jade, & NodeJS: Navigate between pages

如何创建一个有两个按钮的Jade页面,其中每个按钮都重定向到另一个用Jade制作的页面?

This is the code I made for your question: 这是我为您的问题编写的代码:

server.js server.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.jade

doctype html
html
  head
    title= title
  body
    p hi there!
    button(onclick="move()") newPage
script.
  function move() {
    window.location.href = '/newpage'
  }

anotherpage.jade 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 卢卡

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM