title: redirect in React - Node
body: <p>I watched certain tutorial to understand how to do routing but they all were theoretical or I wasn't able to understand their implementation. </p>
  
  <p>Can someone help me by guiding me to route/re-direct this one component as an example so that I can setup routes for other components as well. </p>
  
  <p>I am using express.js for the server side and react for client side </p>
  
  <p>In my react, I sent a request using axious to my server like this (this happens in stateful signup container)</p>
  
  <pre><code> axios.post('/user', {
          emailAddress: this.state.emailAddress,
              password: this.state.password
          })
        .then((response) =&gt; {
                  if (!response.data.error) {
                      console.log('successful signup')
                  } else {
                      console.log('username already taken')
                  }
              })
          .catch(error =&gt; {
                  console.log('signup error: ')
                  console.log(error)
              })
  </code></pre>
  
  <p>In my server route, I take this data, store in my mongoose and then want to redirect to my login page (or any page). My server route looks like this </p>
  
  <pre><code>router.post("/", function(req, res) {
    console.log("user login post request");
    console.log(req.body.emailAddress)
    User.findOne({username: req.body.emailAddress}, function(err, user){
        if (err) {
          console.log('post error: ', err)
  
          }
        else if (user) {
          console.log("already exsist")
          res.json({
              error: 'user exsist'
          })
        }
        else {
          console.log("here new user")
          User.register(new User({username: req.body.emailAddress }), req.body.password, function(error, user){
            if (error) {
              console.log("error -&gt; Post request from user");
              console.log(error);
            } else {
              req.logIn(user, function (err) {
               if (err) {
                 return next(err);
                     }
                return res.json(user) // send whatever you want or redirect
               });
  
            }
          })
        }
    })
  })
  </code></pre>
  
  <p>In ejs, we used to do res.render but then that is EJS and I doesn't work on react so can someone help me/guide in setting up routes so that if user is successfully registered then we can redirect him to login component. </p>
  
  <p>The least I have already done is npm install react-router-dom --save</p>