Logo Questions Linux Laravel Mysql Ubuntu Git Menu

change url on res.redirect in expressjs

app.get('/logout', function (req, res){

    console.log('req.url is ' + req.url);

    req.session.state = null;


upon redirect, the 'url' remains the same. I want it to change it too. Which i tried to do using req.url. But it does not reflect on the url-bar. How do you change that?

Note:- I'm using Angularjs Routing so the res.redirect is not automatically updating the url.

Edit:- Angular Code:-

$http({method: 'GET', url: '/logout'}).
        success(function(data, status, headers, config) {

        error(function(data, status, headers, config) {
          // called asynchronously if an error occurs
          // or server returns response with an error status.
like image 644
Sangram Singh Avatar asked Mar 22 '23 21:03

Sangram Singh

1 Answers

By default res.redirect will send a response with a 302 status code and a Location header with the URL you call the function with. So in your case something like:

HTTP/1.1 302 
Location: http://example.com/login/

You will need to handle this on the AngularJS side to change the URL.

like image 186
Brett Avatar answered Mar 24 '23 10:03