title: Navigating to a page on load in react JS
body: <p>I am working on user registration setup and stuck on a problem where I am not able to redirect from a page 'localhost:3000/activate/tokenNo.'(Activation.jsx file) on load to my main page (App.jsx file) .</p>
  <p>Here is my activation.jsx file :</p>
  <pre><code>import React, { useEffect } from 'react';
  import { useNavigate } from &quot;react-router-dom&quot;;
  
  
  const Activate = () =&gt; {
      const navigate = useNavigate();
  
      useEffect(() =&gt; {
          navigate('/')
      }, [navigate])
  
      return (
          &lt;div&gt;Activation Page&lt;/div&gt;
      )
  }
  
  export default Activate;
  </code></pre>
  <p>Here is my App.jsx file :</p>
  <pre><code>import React from 'react';
  
  export const App = () =&gt; {
    return &lt;div&gt;Dashboard&lt;/div&gt;;
  };
  export default App ;
  </code></pre>
  <p>My activationController.js file :</p>
  <pre><code>exports.activationController = (req,res) =&gt; {
      const {token} = req.body 
      if(token){
          //Verify the token is valid or not or expired
      jwt.verify(token , process.env.JWT_ACCOUNT_ACTIVATION , 
          (err , decoded) =&gt; {
              if(err){
                  return res.status(401).json({
                      error: &quot;Expired Token , Signup again&quot;
                  })
              }
              else{
                  //if valid save to database
                  //Get name email password from token
                  const {name , email , password} = jwt.decode(token)
          
                  const user = new User({
                      name , 
                      email ,
                      passsword
                  })
          
                  user.save((err,user) =&gt; {
                      if(err){
                          return res.status(401).json({
                              error: errorHandler(err)
                          })
                      }
                      else{
                          return res.json({
                              success: true , 
                              message: &quot;Signup successful&quot;,
                              user
                          })
                      }
                  })
          
              }
          })
          
      }
      else{
          return res.json({
              message: &quot;error happening please try again&quot;
          })
      }
      
  }
  </code></pre>
  <p>In my auth.routes.js</p>
  <pre><code>router.post('/activation', activationController)
  </code></pre>
  <p>I recieved an error in my console --&gt; index.tsx:25 No routes matched location &quot;/activate/tokenNo.&quot;</p>
  <p>My reference folder --&gt; <a href="https://github.com/Mohammed-Abdelhady/FULL-MERN-AUTH-Boilerplate" rel="nofollow noreferrer">https://github.com/Mohammed-Abdelhady/FULL-MERN-AUTH-Boilerplate</a></p>