I have following routes in nodejs
here is users.js
route
router.post('/users/login', function(request, response) {
// let user login here and do all of the logic.
// Once done then redirect user to dashboard in dashboard.js file
response.redirect('/dashboard');
});
here is dashboard.js route
router.get('/dashboard', function(request, response) {
response.render('plans');
});
Now when I login as a user when it tries to redirect me it says following.
cannot get Cannot GET /users/dashboard
I want users' to redirect to /dashboard/dashboard
instead.
How can I redirect users from one route to another in Express?
Don't do response.redirect('/dashboard');
with a /
in it, as this will add /dashboard
to the current url. Do this instead: response.redirect('dashboard');
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With