feat: 404 page redirect with toast added
This commit is contained in:
@@ -248,6 +248,7 @@
|
|||||||
"zimbabwe": "Zimbabwe"
|
"zimbabwe": "Zimbabwe"
|
||||||
},
|
},
|
||||||
"messages": {
|
"messages": {
|
||||||
|
"pageNotFound": "Page not found",
|
||||||
"noResualtFound": "No result found.",
|
"noResualtFound": "No result found.",
|
||||||
"serverError": "Internal server error"
|
"serverError": "Internal server error"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -185,6 +185,7 @@
|
|||||||
"zimbabwe": "زیمبابوه"
|
"zimbabwe": "زیمبابوه"
|
||||||
},
|
},
|
||||||
"messages": {
|
"messages": {
|
||||||
|
"pageNotFound": "صفحه مورد نظر پیدا نشد.",
|
||||||
"noResualtFound": "نتیجه ای یافت نشد.",
|
"noResualtFound": "نتیجه ای یافت نشد.",
|
||||||
"serverError": "خطای سمت سرور"
|
"serverError": "خطای سمت سرور"
|
||||||
},
|
},
|
||||||
|
|||||||
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} />;
|
||||||
|
};
|
||||||
@@ -5,9 +5,9 @@ import App from './App';
|
|||||||
import { AppProviders } from './providers/AppProvider';
|
import { AppProviders } from './providers/AppProvider';
|
||||||
|
|
||||||
createRoot(document.getElementById('root')!).render(
|
createRoot(document.getElementById('root')!).render(
|
||||||
<StrictMode>
|
// <StrictMode>
|
||||||
<AppProviders>
|
<AppProviders>
|
||||||
<App />
|
<App />
|
||||||
</AppProviders>
|
</AppProviders>,
|
||||||
</StrictMode>,
|
// </StrictMode>,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Layout } from '@/components';
|
import { Layout } from '@/components';
|
||||||
|
import { NavigateWithToast } from '@/components/NavigateWithToast';
|
||||||
import { AccountCreatedPage } from '@/features/authorization/routes/AccountCreatedPage';
|
import { AccountCreatedPage } from '@/features/authorization/routes/AccountCreatedPage';
|
||||||
import {
|
import {
|
||||||
Calendar,
|
Calendar,
|
||||||
@@ -65,6 +66,17 @@ export interface RouteConfig {
|
|||||||
|
|
||||||
// can lazy load component if needed (ex. lazy(() => import('@/features/home/routes/HomePage'));)
|
// can lazy load component if needed (ex. lazy(() => import('@/features/home/routes/HomePage'));)
|
||||||
export const appRoutes: RouteConfig[] = [
|
export const appRoutes: RouteConfig[] = [
|
||||||
|
{
|
||||||
|
path: '*',
|
||||||
|
element: (
|
||||||
|
<NavigateWithToast
|
||||||
|
to="/setting/profile"
|
||||||
|
replace
|
||||||
|
message="messages.pageNotFound"
|
||||||
|
severity="error"
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
element: <Navigate to="/setting/profile" replace />,
|
element: <Navigate to="/setting/profile" replace />,
|
||||||
|
|||||||
Reference in New Issue
Block a user