Nextjs 动态页面路由:在页面变量中使用扩展运算符 [...example] 或 [[...example]] 的目的是什么?

Nextjs dynamic page routes: What is the purpose of using the spread operator [...example] or [[...example]] in a page variable?

我目前正在学习 Nextjs 框架。我会说我已经对这些概念有了扎实的掌握,但还有一些事情我不确定。其中之一是动态页面中的扩展运算符 [...var][[...var]] |路由文件名。

例如 next/auth docs 中的这一行:

pages/api/auth/[...nextauth].js

是否有一些具体的用例(使用 getStaticPaths() 无法实现),或者它只是一个我不知道的命名约定?

pages/api/auth/[...nextauth].js 是一个 catch-all route,这意味着它将匹配 /api/auth/a,但也匹配 /api/auth/a/b/api/auth/a/b/c 等等。

[[...nextauth]].js 将是 optional catch all route。因此,除了上面的常规 catch-all 路由外,它还会匹配 /api/auth.