Este es el código de un proyecto en el que trabajé hace un tiempo, pero ahora que lo miro, ya no se ejecuta debido a cambios en el react-router-dom. Intenté cambiar el interruptor a rutas y la redirección para navegar, sin embargo, no tuve suerte. Si alguien pudiera ayudarme con este problema sería muy apreciado! Código del tutorial de JWT en youtube: https://www.youtube.com/watch?v=cjqfF5hyZFg
const [isAuthenticated, setIsAuthenticated] = useState(false); const setAuth = boolean => { setIsAuthenticated(boolean); }; return ( <Fragment> <Router> <div className="container"> <Switch> <Route exact path="/login" render={props => !isAuthenticated ? ( <Login {...props} setAuth={setAuth} /> ) : ( <Redirect to="/dashboard" /> ) } /> <Route exact path="/register" render={props => !isAuthenticated ? ( <Register {...props} setAuth={setAuth} /> ) : ( <Redirect to="/dashboard" /> ) } /> <Route exact path="/dashboard" render={props => isAuthenticated ? ( <Dashboard {...props} setAuth={setAuth} /> ) : ( <Redirect to="/login" /> ) } /> </Switch> </div> </Router> </Fragment> ); }```