Home > Enterprise >  Node.js button link to page in the same folder
Node.js button link to page in the same folder

Time:04-11

In node.js, how do you link to another page in the same folder like you can with html? I tried the following code to link to thankyou.ejs file in the same folder, it doesn't seem to work

<a  href="thankyou.ejs" role="button">Submit</a>

CodePudding user response:

First, you will have to create a route to thankyou. Remember you don't link pages, rather a route.

Suppose your server looks like this:

// server.js
var express = require('express');
var app = express();

// set the view engine to ejs
app.set('view engine', 'ejs');

// use res.render to load up an ejs view file

// index page
app.post('/thankyou', function(req, res) {
  res.render('pages/thankyou');
});

app.listen(8080);
console.log('Server is listening on port 8080');

Then you can easily refer to the page as:

<a  href="thankyou" role="button">Submit</a>
  • Related