res.redirect does not redirect in expressjs

Asked

Viewed 295 times

0

I am the nodejs along with the expressjs and in the submission of a form a request is made on the server, which after processed, redirects the page:

...

Post.create(doc, (err, post) => {
    if (err || !post) {
        return res.json({
            status: 'error',
            error: err
        });
    }
    post.save()

    res.redirect('/minha-url')
});
...

But the redirect is not done, although in the devtools panel of Chrome, in the networking tab the redirect appears with status 200, as a request.

I don’t understand what the problem is.

I appreciate any help.

  • 1

    You’re doing a post with action form? You can join HTML?

1 answer

0

I was doing the post from ajax and not from a form. With this, instead of user the res.redirect('route'), I just got the route from the server and used on the client side a

window.location = route;

to redirect.

Browser other questions tagged

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