Redirect from one route to another in Express

前端 未结 2 1389
野趣味
野趣味 2021-02-05 22:14

I have following routes in nodejs

here is users.js route

router.post(\'/users/login\', function(request, response) {
    // let user login h         


        
2条回答
  •  佛祖请我去吃肉
    2021-02-05 22:50

    res.redirect('auth/login');
    

    I had this in one of my route named 'contributions' and when it is redirected, it is rendered as 'contributions/auth/login' which is wrong.

    The main thing i needed was 'localhost://port/auth/login.

    i changed my ejs anchor tag to '/auth/login' which will take url from the root, It previously was 'auth/login' which took the url as current url + provided url, i.e., 'contributions/auth/login' in my case.

    Hope this helps.

提交回复
热议问题