Skip to content
Advertisement

Express APP how to redirect user to /:id path from server side

I’m learning Node.js and I’m finding some troubles with redirecting the user to an :id path. I would like to print there his username. So to make an overview it is a landing page with a form where I ask for an Alias and an email. When user clicks submit I’d like to move him to /:id path to print its’ username. My code is the following:

JavaScript

error is the following: { CastError: Cast to ObjectId failed for value “:id” at path “_id” for model “user”

I’ve tried: – to change the path to :_id – added start/ into the route

Advertisement

Answer

When you are using the redirect() method, you must pass a real route url not an id.

JavaScript
Advertisement