score:1

Accepted answer

the redirection is made even before the call to the api is made. useeffect is called after the component has rendered. a solution would be to add an intermediary value, like null or you let it undefined, it's just a way to know whether the call to the api has already been made or not.

const [permissions, setpermissions] = usestate(null);

// ...

if (permissions === null) return null

// ...

{permissions ? <route {...rest} /> : <redirect to="/" />}

Related Query

More Query from same tag