Maintain req.body parameters when changing course

Asked

Viewed 162 times

1

Hello, my question is this::

I am using Express/bodyParser and Nunjucks. I submitted a form with the method POST from my root route '/'.

In the form I have two dice:

  • Username
  • Date of birth

In the post I submit the form I can do a check, for example, what the age of the user. If he’s older, I redirect him to route X if he’s underage I redirect him to Y.

My doubt is precisely on this route X and Y. How do I bring the name that the user submitted in this request for a new route?

I’m using redirect to send it to X or Y.

1 answer

0

You can pass the parameters as follows:

res.redirect(`/nova_rota?nome=${nome}&data=${data}`);

There are other ways, just read the redirect documentation

  • Daniel, I tried to do as you said it returns "name is not defined" when it redirects. I thought I could pass as I step variables to the view: res.redirect('/major', { name: name}); but it is not possible.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.