Express, Jade, & NodeJS: Navigate between pages

早过忘川 提交于 2019-12-03 17:01:22

This is the code I made for your question:

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

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.

Luca

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!