PracticeKea-UI/src/component/PublicRoute.jsx

21 lines
718 B
React
Raw Normal View History

2025-10-27 14:46:51 +00:00
import React from 'react';
import { Route, Redirect } from 'react-router-dom';
import history from '../history';
import { authenticationService } from '../_services';
export const PublicRoute = ({ component: Component, restricted, ...rest }) => (
<Route {...rest} render={props => {
const currentUser = authenticationService.currentUserValue;
if (currentUser) {
//history.push("/dashboard");
// not logged in so redirect to login page with the return url
return <Redirect to={{ pathname: '/dashboard', state: { from: props.location } }} />
}else{
}
// authorised so return component
return <Component {...props} />
}} />
)