Express, Jade, and NodeJS: Navigating Between Pages

How to create a Jade page that has two buttons, each of which is redirected to another page using Jade?

+5
source share
1 answer

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 a message.

Luke

+14
source

Source: https://habr.com/ru/post/1214925/


All Articles