Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

create-react-app react routing protected routes

import { Outlet, Navigate } from 'react-router-dom'

const PrivateRoutes = () => {
    let auth = localStorage.token
    if (!auth){
       return(<Navigate to="/login"/>) 
    }else {
        return(<Outlet/>)
    }

}

export default PrivateRoutes
Source by thinkpanda.hashnode.dev #
 
PREVIOUS NEXT
Tagged: #react #routing #protected #routes
ADD COMMENT
Topic
Name
3+3 =