Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect to another path in Node JS route

In Node Js route.js when user try to open

app.use('/demo1', require('express').static(__dirname + '/demo1'));

then i want to redirect to

app.use('/demo2', require('express').static(__dirname + '/demo2'));

like In the browser user type http://locahhost:5010/demo1 this URL

but it will open http://locahhost:5010/demo2 this URL

like image 805
Anupam Avatar asked Dec 12 '16 06:12

Anupam


People also ask

How do I redirect a login page in node JS?

user = o; res. redirect('/home'); } else{ res. render('/login', { title: 'Hello - Please Login To Your Account' }); } }); } }); After that, all other html websites are linked from within dashboard.

What is the use redirect () function?

redirect() function redirects to the URL derived from the specified path, with specified status, a integer (positive) which corresponds to an HTTP status code. The default status is “302 Found”.


1 Answers

Use redirect in your route Express redirect

Example:

app.get('/demo1', function(req, res) {
 res.redirect('/demo2');
});
like image 159
Vikramaditya Avatar answered Oct 02 '22 16:10

Vikramaditya