Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Commit c92f335

Browse files
committed
perf: Add redirect to faq when not found page in faq
1 parent d03ec81 commit c92f335

File tree

13 files changed

+237
-223
lines changed

13 files changed

+237
-223
lines changed

app/[locale]/(main)/faq/[id]/[childId]/page.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { notFound } from 'next/navigation';
21
import { Suspense, lazy } from 'react';
32
import { Metadata } from 'next';
4-
import { getTranslator } from 'next-intl/server';
3+
import { getTranslator, redirect } from 'next-intl/server';
54

65
import { LoadingView } from '@/views/global/loading/LoadingView';
6+
import { faqData } from '@/views/faq/faqData';
77

88
interface Props {
99
params: {
@@ -18,16 +18,21 @@ export async function generateMetadata({
1818
}: Props): Promise<Metadata> {
1919
const t = await getTranslator(locale, 'faq');
2020

21+
const isDataExist = faqData.find(data => data.id === id)?.items.find(item => item.id === childId);
22+
if (!isDataExist) {
23+
redirect('/faq');
24+
}
25+
2126
return {
2227
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2328
// @ts-expect-error
24-
title: t(`pages.${id}_pages.${childId}`)
29+
title: t(`pages.${id}.${childId}`)
2530
};
2631
}
2732

2833
export default async function Page({ params: { childId, id, locale } }: Props) {
2934
const MDXComponent = lazy(() =>
30-
import(`@/assets/faq/${id}/${childId}/${childId}-${locale}.mdx`).catch(() => notFound())
35+
import(`@/assets/faq/${id}/${childId}/${childId}-${locale}.mdx`).catch(() => redirect('/faq'))
3136
);
3237

3338
return (

app/[locale]/(main)/faq/[id]/page.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { notFound } from 'next/navigation';
21
import { Suspense, lazy } from 'react';
32
import { Metadata } from 'next';
4-
import { getTranslator } from 'next-intl/server';
3+
import { getTranslator, redirect } from 'next-intl/server';
54

65
import { LoadingView } from '@/views/global/loading/LoadingView';
6+
import { faqData } from '@/views/faq/faqData';
77

88
interface Props {
99
params: {
@@ -15,16 +15,24 @@ interface Props {
1515
export async function generateMetadata({ params: { id, locale } }: Props): Promise<Metadata> {
1616
const t = await getTranslator(locale, 'faq');
1717

18+
const isDataExist = faqData
19+
.map(data => data.items)
20+
.flat()
21+
.find(item => item.id === id);
22+
if (!isDataExist) {
23+
redirect('/faq');
24+
}
25+
1826
return {
1927
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2028
// @ts-expect-error
21-
title: t(`pages.${id}`)
29+
title: t(`pages.global.${id}`)
2230
};
2331
}
2432

2533
export default async function Page({ params: { id, locale } }: Props) {
2634
const MDXComponent = lazy(() =>
27-
import(`@/assets/faq/${id}/${id}-${locale}.mdx`).catch(() => notFound())
35+
import(`@/assets/faq/${id}/${id}-${locale}.mdx`).catch(() => redirect('/faq'))
2836
);
2937

3038
return (
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# PSD Files
2+
3+
Can I build apps from your PSD files?
4+
5+
> Yes, but it increases the cost of the license about 150%-200%. It's old technology. I recomended you to use Sketch or Figma.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Pliki PSD
2+
3+
Czy mogę budować aplikacje z Twoich plików PSD?
4+
5+
> Tak, ale zwiększa to koszt licencji o około 150-200%. To stare narzędzie do projektowania. Zalecam korzystanie z Figmy lub Sketch.

messages/en.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,17 @@
135135
}
136136
},
137137
"faq": {
138-
"collaboration": "Collaboration",
139138
"menu": "Menu",
140139
"pages": {
141-
"welcome": "Welcome",
142-
"technology": "Technology & Tools",
143-
"collaboration": "Collaboration",
144-
"collaboration_pages": {
140+
"global": {
141+
"welcome": "Welcome",
142+
"technology": "Technology & Tools"
143+
},
144+
"collaboration": {
145+
"title": "Collaboration",
145146
"get_started": "Get Started",
146-
"vat": "Vat Invoice"
147+
"vat": "Vat Invoice",
148+
"psd_files": "PSD Files"
147149
}
148150
}
149151
}

messages/pl.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,17 @@
135135
}
136136
},
137137
"faq": {
138-
"collaboration": "Współpraca",
139138
"menu": "Menu",
140139
"pages": {
141-
"welcome": "Witaj",
142-
"technology": "Technologie i narzędzia",
143-
"collaboration": "Współpraca",
144-
"collaboration_pages": {
140+
"global": {
141+
"welcome": "Witaj",
142+
"technology": "Technologie i narzędzia"
143+
},
144+
"collaboration": {
145+
"title": "Współpraca",
145146
"get_started": "Zacznijmy",
146-
"vat": "Faktura VAT"
147+
"vat": "Faktura VAT",
148+
"psd_files": "Pliki PSD"
147149
}
148150
}
149151
}

next.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ const withMDX = require('@next/mdx')();
77

88
const nextConfig = {
99
...withBundleAnalyzer(),
10-
experimental: {
11-
mdxRs: true
12-
},
1310
images: {
1411
formats: ['image/avif', 'image/webp'],
1512
remotePatterns: [

0 commit comments

Comments
 (0)