21 lines
718 B
JavaScript
21 lines
718 B
JavaScript
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} />
|
|
}} />
|
|
) |