import React from "react"; import {Redirect, Route as ReactRouterDOMRoute, type RouteComponentProps, type RouteProps} from "react-router-dom"; import {ErrorBoundary} from "./ErrorBoundary"; import {app} from "../app"; interface Props extends RouteProps { component: React.ComponentType> | React.ComponentType; // All below are optional withErrorBoundary: boolean; accessCondition: boolean; unauthorizedRedirectTo: string; notFound: boolean; } export class Route extends React.PureComponent { static defaultProps: Pick = { exact: true, sensitive: true, withErrorBoundary: true, accessCondition: true, unauthorizedRedirectTo: "/", notFound: false, }; renderRegularRouteComponent = (props: RouteComponentProps): React.ReactElement => { const {component, accessCondition, unauthorizedRedirectTo, notFound, withErrorBoundary} = this.props; if (accessCondition) { const WrappedComponent = notFound ? withNotFoundWarning(component) : component; const routeNode = ; return withErrorBoundary ? {routeNode} : routeNode; } else { return ; } }; override render() { const {component, ...restRouteProps} = this.props; return ; } } function withNotFoundWarning(WrappedComponent: React.ComponentType): React.ComponentType { return class extends React.PureComponent { override componentDidMount() { app.logger.warn({ action: "@@framework/route-404", elapsedTime: 0, errorMessage: `${location.href} not supported by `, errorCode: "ROUTE_NOT_FOUND", info: {}, }); } override render() { return ; } }; }