Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Keycloak react private route that accepts a route with params, possible answer to this question https://github.com/the-glue/react-router-keycloak/issues/7
<PrivateRoute exact path="/props-through-render" render={(props) => <PropsPage {...props} title={`Props through render`} />} />
import React from 'react';
import { Route } from 'react-router-dom';
import { withKeycloak } from '@react-keycloak/web'
function PrivateRoute({ ...rest }) {
return rest.keycloakInitialized && <Route {...rest} render={props => (
rest.keycloak.authenticated ? rest.render(props) : rest.keycloak.login()
)} />
}
export default withKeycloak(PrivateRoute)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment