quinnz commited on
Commit
0453799
·
1 Parent(s): 71064f7

fix 404 error

Browse files
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 '../../lib/mdx' // 用相对路径
4
 
5
  export default async function DocPage({ params }: { params: { lang: string; slug: string[] } }) {
6
- const mdxPath = getMdxPath(params.lang, params.slug)
 
 
7
  if (!mdxExists(mdxPath)) notFound()
8
 
9
  const Page = dynamic(() =>
10
- import(`../../content/${params.lang}/${params.slug.join('/')}.mdx`).then(mod => mod.default)
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(p: string) {
9
- return fs.existsSync(p)
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
- const withMDX = createMDX({
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
- "exclude": ["node_modules"]
14
- }
 
1
  {
2
  "compilerOptions": {
 
 
3
  "baseUrl": ".",
4
  "paths": {
5
  "@/*": ["./*"]
6
+ }
 
 
7
  },
8
+ "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.mdx"]
9
+ }