next-route

在目录结构中,我们精心创建的每一个文件最终都会经过处理,转化为相应的页面路由。然而,值得注意的是,某些特殊文件格式在生成过程中并不会被当作路由路径来处理。

app
 |-auth
     login
       page.tsx
     password
       page.tsx
//最后生成的路由路径
//·localhost:3000/auth/login 
//·localhost:3000/auth/password
       
       
//()路由组的作用在编译的时候会忽略       
app
  (auth)
      login
          page.tsx
      password
          page.tsx   
//最后生成的路由路径 
//·localhost:3000/login 
//·localhost:3000/password

//[]的作用 动态路由
app
  auth
      [dynamic]
          page.tsx
//最后生成的路由路径 
//·localhost:3000/auth/1 
//·localhost:3000/auth/2  
//因为他在 auth 文件下 所有在路径匹配 auth时,他的下一级都回访问到 [dynamic]的页面





//[...]的作用 多级动态路由
app
  auth
      [...slug]
          page.tsx
//最后生成的路由路径 
//·localhost:3000/auth/1 
//·localhost:3000/auth/1/docs  
//·localhost:3000/auth/1/docs/1
//因为他在 auth 文件下 所有在路径匹配 auth时,他的后续路由都回访问到 [...slug]的页面
posted @ 2024-05-15 09:19  攀上顶峰  阅读(15)  评论(0编辑  收藏  举报