Skip to content

Instantly share code, notes, and snippets.

@Lxxyx
Last active June 17, 2021 09:50
Show Gist options
  • Save Lxxyx/c128c25b5344e6f552d578329bae9f79 to your computer and use it in GitHub Desktop.
Save Lxxyx/c128c25b5344e6f552d578329bae9f79 to your computer and use it in GitHub Desktop.
文件路由 Params 设计
// 默认情况
// /lambda/article/[id].ts
export default async (id: string) => {
return id
}
export const content = (id: string) => {
// id = req.params.id = 路径
return id
}
// GET /api/article/MarkTwain => MarkTwain
// GET /api/article/Hemingway/content => Hemingway
// 嵌套
// /lambda/[user]/history/[year].ts
export default async (user: string, year: string) => {
return id
}
// 可以匹配,/api/jack/history/35,req.params = { user: jack, year: 35 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment