© 2026 LinearBytes Inc.
Search posts, tags, users, and pages
Nishant Sahoo
You tell me.
Even Hashnode does authorization and is based on ReactJS. I wanted to know which library is being used for the same.
My end goal is to authorize users and have authorized routing in my application built using ReactJS.
you can create your custom component for authorization and used like this
<PrivateRoute path="/login" component={Login} if={!isLogged()} redirect="/" />
see this component take if as props, and here you can put your condition.
if
and this is how your custom component look like
import React from 'react' import { Redirect, Route } from 'react-router-dom' const PrivateRoute = props => { const condition = props.if const Component = props.component const redirect = props.redirect return ( condition ? <Route path={props.path} component={Component} /> : <Redirect to={redirect} /> ) } export default PrivateRoute
Mohamed Binothman
Web Developer
Ryosuke
Designer / Developer / Influencer
I'd go with this answer. It's another version of what's recommended in the React Router docs for authenticated routes.
you can create your custom component for authorization and used like this
<PrivateRoute path="/login" component={Login} if={!isLogged()} redirect="/" />see this component take
ifas props, and here you can put your condition.and this is how your custom component look like
import React from 'react' import { Redirect, Route } from 'react-router-dom' const PrivateRoute = props => { const condition = props.if const Component = props.component const redirect = props.redirect return ( condition ? <Route path={props.path} component={Component} /> : <Redirect to={redirect} /> ) } export default PrivateRoute