1

I want to redirect to a page where the path is like /users/home/:id

   response.redirect('/users/home')

The above code will redirect to /users/home but I want to redirect it to a page like '/users/home/1' dynamically with parameters. How shall I solve it?Do explain with some examples

1 Answer 1

1

You could use template literals to form the new url, for example:

app.get("/users/home/:id", (req, res) => { 
    res.redirect(`/users/alternate_home/${req.params.id}`);
});

app.get("/users/alternate_home/:id", (req, res) => { 
    res.json(users);
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.