WillemvanderVeen WillemvanderVeen - 3 years ago 282
Javascript Question

Navigation using express and EJS

Having a issue figuring out how to navigate between EJS pages effectively:

File directory:

enter image description here

I want to go from my index.ejs page to the about.ejs page. This is the code for my index.ejs page which is currently not navigating properly:


<!DOCTYPE html>
<h1> <a href="about.ejs"> This is a link to about page</a></h1>

app.js server:

const express = require("express");
const path = require('path');
const app = express();

app.set("views", path.resolve(__dirname, "views"));
app.set("view engine", "ejs")

app.get("/", (req, res) => {



What could I enter in the href to properly reference the dynamic about.ejs file?
I already know that I can reference static files from my public folder but I want to refernce the dynamic ejs folder. If not possible any solution which provides the same functionality will also do.

Answer Source

You should render about.ejs template to use it on the client. To do that, you need to create a new route:

app.get("/about", (req, res) => {

To open it use /about path.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download