fix 404 error
Browse files- app/.DS_Store +0 -0
- app/[lang]/[...slug]/page.tsx +5 -3
- lib/mdx.ts +3 -3
- next.config.mjs +3 -11
- tsconfig.json +3 -8
app/.DS_Store
DELETED
|
Binary file (6.15 kB)
|
|
|
app/[lang]/[...slug]/page.tsx
CHANGED
|
@@ -1,13 +1,15 @@
|
|
| 1 |
import { notFound } from 'next/navigation'
|
| 2 |
import dynamic from 'next/dynamic'
|
| 3 |
-
import { getMdxPath, mdxExists } from '
|
| 4 |
|
| 5 |
export default async function DocPage({ params }: { params: { lang: string; slug: string[] } }) {
|
| 6 |
-
const
|
|
|
|
|
|
|
| 7 |
if (!mdxExists(mdxPath)) notFound()
|
| 8 |
|
| 9 |
const Page = dynamic(() =>
|
| 10 |
-
import(`
|
| 11 |
)
|
| 12 |
|
| 13 |
return <Page />
|
|
|
|
| 1 |
import { notFound } from 'next/navigation'
|
| 2 |
import dynamic from 'next/dynamic'
|
| 3 |
+
import { getMdxPath, mdxExists } from '@/lib/mdx'
|
| 4 |
|
| 5 |
export default async function DocPage({ params }: { params: { lang: string; slug: string[] } }) {
|
| 6 |
+
const { lang, slug } = params
|
| 7 |
+
const mdxPath = getMdxPath(lang, slug)
|
| 8 |
+
|
| 9 |
if (!mdxExists(mdxPath)) notFound()
|
| 10 |
|
| 11 |
const Page = dynamic(() =>
|
| 12 |
+
import(`@/content/${lang}/${slug.join('/')}.mdx`).then(mod => mod.default)
|
| 13 |
)
|
| 14 |
|
| 15 |
return <Page />
|
lib/mdx.ts
CHANGED
|
@@ -5,6 +5,6 @@ export function getMdxPath(lang: string, slug: string[]) {
|
|
| 5 |
return path.join(process.cwd(), 'content', lang, ...slug) + '.mdx'
|
| 6 |
}
|
| 7 |
|
| 8 |
-
export function mdxExists(
|
| 9 |
-
return fs.existsSync(
|
| 10 |
-
}
|
|
|
|
| 5 |
return path.join(process.cwd(), 'content', lang, ...slug) + '.mdx'
|
| 6 |
}
|
| 7 |
|
| 8 |
+
export function mdxExists(mdxPath: string) {
|
| 9 |
+
return fs.existsSync(mdxPath)
|
| 10 |
+
}
|
next.config.mjs
CHANGED
|
@@ -1,22 +1,14 @@
|
|
| 1 |
-
import createMDX from '@next/mdx'
|
| 2 |
import path from 'path'
|
| 3 |
import { fileURLToPath } from 'url'
|
|
|
|
| 4 |
|
| 5 |
-
// ESM 下获取项目根目录
|
| 6 |
const __filename = fileURLToPath(import.meta.url)
|
| 7 |
const __dirname = path.dirname(__filename)
|
| 8 |
|
| 9 |
-
|
| 10 |
-
extension: /\.mdx$/,
|
| 11 |
-
})
|
| 12 |
-
|
| 13 |
-
/** @type {import('next').NextConfig} */
|
| 14 |
-
const nextConfig = withMDX({
|
| 15 |
pageExtensions: ['ts', 'tsx', 'mdx'],
|
| 16 |
webpack(config) {
|
| 17 |
config.resolve.alias['@'] = path.resolve(__dirname)
|
| 18 |
return config
|
| 19 |
},
|
| 20 |
-
})
|
| 21 |
-
|
| 22 |
-
export default nextConfig
|
|
|
|
|
|
|
| 1 |
import path from 'path'
|
| 2 |
import { fileURLToPath } from 'url'
|
| 3 |
+
import withMDX from '@next/mdx'
|
| 4 |
|
|
|
|
| 5 |
const __filename = fileURLToPath(import.meta.url)
|
| 6 |
const __dirname = path.dirname(__filename)
|
| 7 |
|
| 8 |
+
export default withMDX({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
pageExtensions: ['ts', 'tsx', 'mdx'],
|
| 10 |
webpack(config) {
|
| 11 |
config.resolve.alias['@'] = path.resolve(__dirname)
|
| 12 |
return config
|
| 13 |
},
|
| 14 |
+
})
|
|
|
|
|
|
tsconfig.json
CHANGED
|
@@ -1,14 +1,9 @@
|
|
| 1 |
{
|
| 2 |
"compilerOptions": {
|
| 3 |
-
"target": "ESNext",
|
| 4 |
-
"module": "ESNext",
|
| 5 |
"baseUrl": ".",
|
| 6 |
"paths": {
|
| 7 |
"@/*": ["./*"]
|
| 8 |
-
}
|
| 9 |
-
"strict": true,
|
| 10 |
-
"jsx": "preserve"
|
| 11 |
},
|
| 12 |
-
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.mdx"]
|
| 13 |
-
|
| 14 |
-
}
|
|
|
|
| 1 |
{
|
| 2 |
"compilerOptions": {
|
|
|
|
|
|
|
| 3 |
"baseUrl": ".",
|
| 4 |
"paths": {
|
| 5 |
"@/*": ["./*"]
|
| 6 |
+
}
|
|
|
|
|
|
|
| 7 |
},
|
| 8 |
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.mdx"]
|
| 9 |
+
}
|
|
|