如何在Next 13中创建带下划线的路由?

huangapple go评论81阅读模式
英文:

How can i create a route with underscore in next 13?

问题

我想创建一个以下划线开头的URL地址,但是我不能,因为next.js文档说它是一个私有文件夹!
我该怎么做呢?
示例:/shop/_t-shirt

英文:

I want to create a URL address that start with an underscore but i cant because next.js dacument said it was a private folder!
how can i do it?
example: /shop/_t-shirt

答案1

得分: 4

在第13版本中,Next.js提到了一种方法,您可以创建以下划线开头的URL段

https://nextjs.org/docs/app/building-your-application/routing/colocation
> 您可以通过在文件夹名称前缀中使用 %5F(下划线的URL编码形式)来创建以下划线开头的URL段: %5FfolderName。

所以您可以这样做:

/app
  /shop
  /%5Ft-shirt
    page.tsx
英文:

In version 13, Next.js mentioned a way that you can create URL segments that start with an underscore

https://nextjs.org/docs/app/building-your-application/routing/colocation
>You can create URL segments that start with an underscore by prefixing the folder name with %5F (the URL-encoded form of an underscore): %5FfolderName.

so you can do it:

/app
  /shop
  /%5Ft-shirt
    page.tsx

huangapple
  • 本文由 发表于 2023年7月31日 21:42:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76804228.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定