27 lines
699 B
TypeScript
27 lines
699 B
TypeScript
'use client';
|
|
|
|
import { useEffect } from 'react';
|
|
import { useRouter } from '@/components/navigation';
|
|
|
|
export default function AutoRedirect() {
|
|
const router = useRouter();
|
|
|
|
useEffect(() => {
|
|
// Get current pathname without locale
|
|
const pathname = window.location.pathname;
|
|
const segments = pathname.split('/').filter(Boolean);
|
|
|
|
// Check if first segment is a locale
|
|
const locales = ['in', 'en', 'ar'];
|
|
const hasLocale = segments.length > 0 && locales.includes(segments[0]);
|
|
|
|
if (!hasLocale) {
|
|
// Redirect to default locale with current path
|
|
const newPath = `/in${pathname}`;
|
|
router.replace(newPath);
|
|
}
|
|
}, [router]);
|
|
|
|
return null;
|
|
}
|