Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Express dynamically display associated page

I have a simple express app.

The problem i have now is when any of the navigation link (Home, Home1, Home2) is clicked, it’s returning an error but if i type http://localhost:8001/home1 -> it will display home1.html.

so, what i wanted is, by the time user click one of the navigation link, it should take them to the appropriate page.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any help, i will highly appreciate.

var express = require("express");
var app = express();
app.use('/temp', express.static(__dirname + '/temp'));

app.get('/home', function(req, res){
  res.sendFile(__dirname + '/temp/home.html')
}) 

enter image description here

>Solution :

Don’t use ./ in your HTML links. Change your links in the HTML to start with / instead so that the links do not depend upon the path of the current page’s URL.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading