feat: 404 page redirect with toast added
This commit is contained in:
24
src/components/NavigateWithToast.tsx
Normal file
24
src/components/NavigateWithToast.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { useToast, type ToastOptions } from '@rkheftan/harmony-ui';
|
||||
import React, { useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Navigate } from 'react-router-dom';
|
||||
|
||||
export interface NavigateWithToastProps extends ToastOptions {
|
||||
to: string;
|
||||
replace?: boolean;
|
||||
translator?: string;
|
||||
}
|
||||
|
||||
export const NavigateWithToast = (props: NavigateWithToastProps) => {
|
||||
const { t } = useTranslation(props.translator ?? 'common');
|
||||
const toast = useToast();
|
||||
|
||||
useEffect(() => {
|
||||
toast({
|
||||
...props,
|
||||
message: t(props.message),
|
||||
});
|
||||
}, []);
|
||||
|
||||
return <Navigate to={props.to} replace={props.replace ? true : false} />;
|
||||
};
|
||||
Reference in New Issue
Block a user