forked from ci4s/knowlegegraph-platform
27 lines
696 B
TypeScript
27 lines
696 B
TypeScript
import React from 'react';
|
|
import { connect } from 'react-redux';
|
|
import { Redirect, Route } from 'react-router-dom';
|
|
|
|
import { IRootState } from './store';
|
|
|
|
const mapState = (state: IRootState) => ({
|
|
host: state.nebula.host,
|
|
username: state.nebula.username,
|
|
});
|
|
|
|
const mapDispatch = () => ({});
|
|
|
|
const PrivateRoute = ({ component: Component, render, ...rest }) => {
|
|
if (rest.host && rest.username) {
|
|
return Component ? (
|
|
<Route {...rest} render={props => <Component {...props} />} />
|
|
) : (
|
|
<Route render={render} {...rest} />
|
|
);
|
|
} else {
|
|
return <Redirect to="/connect-server" {...rest} />;
|
|
}
|
|
};
|
|
|
|
export default connect(mapState, mapDispatch)(PrivateRoute);
|