Home > database >  Move from login page to dashboard after successful login in react js
Move from login page to dashboard after successful login in react js

Time:01-23

using React js I am trying to move from login page to dashboard page but i am not getting the correct way.

CodePudding user response:

Find an example for authorization flows with react-router-dom here:

https://github.com/remix-run/react-router/tree/main/examples/auth

CodePudding user response:

Are you using router? If yes, you can use useNavigate in react-router-dom to navigate to another path when you've done login

Ex:

import {useNavigate} from 'react-router-dom'
...

export default function App(){
   const navaigate = useNavigate()

   const handleLogin = () => {  
      //do something
      ...
      navigate('/dashboard') //or whatever path you wish
   }

   return (
       ....
   )
}

Note: It is only working if your React App using Router

CodePudding user response:

Please refer https://github.com/VickyDhanwani/ReactJS-App/blob/main/src/App.js if you are not using react router. Navigation is based on state and update in state changes the view after validation.

  • Related