NextJS 路由在确定路由时考虑 / 和 %2F

str*_*rks 5 next.js

我有一个像这样的网址: manage/text_U2FsdGVkX1/7AucFzVPX7OpRHb8Dlk/ApiJsTvYroROv4Ds4oshwC+cg3a7Mz/aO 应该由路由/目录处理/pages/manage/[id]

id = test_someEncryptedString

但是由于/这行不通。所以我决定对此进行编码(使用encodeURIComponent),这给了我这个网址: manage/test_U2FsdGVkX1%2F7AucFzVPX7OpRHb8Dlk%2FApiJsTvYroROv4Ds4oshwC%2Bcg3a7Mz%2FaO

在我的本地开发服务器上,这工作正常,但在生产中我得到了 404。我猜 NextJS 仍然认为%2F是 a/并寻找该路线?

有什么办法可以防止这种情况发生吗?

And*_*Gee 0

如果你双重编码/解码,它就可以工作。

let yourValue = encodeURIComponent(encodeURIComponent(yourValue))

// Go to your route, for example:
// router.push(`/page/${yourValue}`)
Run Code Online (Sandbox Code Playgroud)

然后,您可以在服务器端进行双重解码,如下所示:

let yourValue = decodeURIComponent(decodeURIComponent(yourValue))
Run Code Online (Sandbox Code Playgroud)