feat: add product generation and pagination components
- Implemented product generation for categories with a helper function to create 50 products per category. - Added image assets for English and Persian language support. - Created a reusable Pagination component for navigating through product lists. - Developed ProductList component to display products with pagination support. - Defined TypeScript interfaces for product list props and API response structure.
This commit is contained in:
+39
-4
@@ -1,8 +1,43 @@
|
||||
import createMiddleware from 'next-intl/middleware';
|
||||
import { routing } from './i18n/routing';
|
||||
import { NextResponse } from 'next/server';
|
||||
import type { NextRequest } from 'next/server';
|
||||
|
||||
export default createMiddleware(routing);
|
||||
const PUBLIC_FILE = /\.(.*)$/;
|
||||
const locales = ['en', 'fa'];
|
||||
const defaultLocale = 'en';
|
||||
|
||||
export function middleware(request: NextRequest) {
|
||||
const { pathname } = request.nextUrl;
|
||||
|
||||
// Ignore public files and API routes
|
||||
if (pathname.startsWith('/api') || PUBLIC_FILE.test(pathname)) {
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
// Check if the pathname already includes a locale
|
||||
const matchedLocale = locales.find(
|
||||
(locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`,
|
||||
);
|
||||
|
||||
const locale = matchedLocale || defaultLocale;
|
||||
|
||||
let response: NextResponse;
|
||||
|
||||
// If locale is missing, redirect and set cookie
|
||||
const pathnameIsMissingLocale = !matchedLocale;
|
||||
if (pathnameIsMissingLocale) {
|
||||
response = NextResponse.redirect(
|
||||
new URL(`/${defaultLocale}${pathname}`, request.url),
|
||||
);
|
||||
} else {
|
||||
response = NextResponse.next();
|
||||
}
|
||||
|
||||
// Set the locale cookie for all responses
|
||||
response.cookies.set('locale', locale, { path: '/' });
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: '/((?!api|trpc|_next|_vercel|.*\\..*).*)',
|
||||
matcher: ['/((?!_next/static|_next/image|favicon.ico|api).*)'],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user