Path: blob/1.0-develop/resources/scripts/components/elements/PermissionRoute.tsx
7461 views
import React from 'react';1import { Route } from 'react-router-dom';2import { RouteProps } from 'react-router';3import Can from '@/components/elements/Can';4import { ServerError } from '@/components/elements/ScreenBlock';56interface Props extends Omit<RouteProps, 'path'> {7path: string;8permission: string | string[] | null;9}1011export default ({ permission, children, ...props }: Props) => (12<Route {...props}>13{!permission ? (14children15) : (16<Can17matchAny18action={permission}19renderOnError={20<ServerError title={'Access Denied'} message={'You do not have permission to access this page.'} />21}22>23{children}24</Can>25)}26</Route>27);282930