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

I am currently learning the Nextjs framework. I would say I have a solid grasp of the concepts already,

I am currently learning the Nextjs framework. I would say I have a solid grasp of the concepts already, but there are still a few things I am not sure about. One of those things is the spread operator [...var] or [[...var]] in a dynamic page | route file name.

For example this line from next/auth docs:

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

Is there some concrete use case (that can't be achieved using getStaticPaths()), or is it just a naming convention which I don't know about?

I am currently learning the Nextjs framework. I would say I have a solid grasp of the concepts already, but there are still a few things I am not sure about. One of those things is the spread operator [...var] or [[...var]] in a dynamic page | route file name.

For example this line from next/auth docs:

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

Is there some concrete use case (that can't be achieved using getStaticPaths()), or is it just a naming convention which I don't know about?

Share Improve this question asked Apr 14, 2021 at 8:14 HynekSHynekS 3,3372 gold badges23 silver badges41 bronze badges 1
  • 1 this dynamic routing also called dynamic segment which means passing additional parameters through like array. – vishal Commented Mar 9, 2024 at 11:52
Add a ment  | 

1 Answer 1

Reset to default 9

pages/api/auth/[...nextauth].js is a catch-all route which means that it will match /api/auth/a but also /api/auth/a/b, /api/auth/a/b/c and so on.

[[...nextauth]].js would be an optional catch all route. So in addition to the regular catch-all route above it would also match /api/auth.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745346317a4623561.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信