gpt4 book ai didi

next.js - 如何使非英语网址在 next.js 中工作?

转载 作者:行者123 更新时间:2023-12-02 00:06:43 25 4
gpt4 key购买 nike

如何使非英语 url 与 next.js ssr/client 一起工作?欢迎任何想法、重写等。

前段时间重写有助于解决这个问题,但在一些更新后它停止工作。这是我对 fix this 的尝试.

Codesandbox .

我什至尝试过 Unicode 路径(重写),但它给了我奇怪的错误:

{
source: encodeURI('/рус'),
destination: "/u0440/u0443/u0441"
}

Error: Requested and resolved page mismatch: //u0440/u0443/u0441 /u0440/u0443/u0441

最佳答案

现在我在 next.config.js 中像这样重写:

const withBundleAnalyzer = require('@next/bundle-analyzer')({
enabled: process.env.ANALYZE === 'true',
})

const pathsToRewrite = [
['/пользователь/:id/:nickname', '/user/:id/:nickname'],
['тест', 'test'],
]
const rewrites = pathsToRewrite.map(([ru, eng]) => ({ source: encodeURI(ru), destination: eng }))

module.exports = withBundleAnalyzer({
async rewrites() {
return rewrites
},
})

关于next.js - 如何使非英语网址在 next.js 中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60390591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com