I have this simplified code, quite simple:
export const OwnRedirect = () => {
const { pipelineType, ticketId, productId } = useParams<{
pipelineType?: string;
ticketId?: string;
productId?: string;
}>();
let path = '';
if (pipelineType) {
path = `/pipeline/${pipelineType}`;
} else if (ticketId) {
path = `/ticket/${ticketId}`;
} else if (productId) {
path = `/product/${productId}`;
} else {
path = '/pipeline/local';
}
return <Redirect to={path}/>;
};
But I found it not readable enough. Anybody has an idea how to refactor this code not using if
or switch
or let
or nested ternary operator?