我有很多关于我的网站的参考,我正在迁移到以大写字母开头的NextJS,如下所示:
https://svcc.mobi/Presenter/2019/llewellyn-falco-3133 (请注意演示者中的大写P)
我希望他们都重写到
https://svcc.mobi/presenter/2019/llewellyn-falco-3133
我可以像下面这样更新我的next.config.js
以处理单个条目,但是我希望在我的next.config.js
文件中有几千个这样的条目。我能以某种方式在构建时以编程方式加载此数组吗?(类似于getStaticPaths )。
module.exports = {
async rewrites() {
return [
{
source: '/(P|p)resenter/2019/llewellyn-falco-3133',
destination: '/presenter/2019/llewellyn-falco-3133',
},
{
source: '/(a|A)(b|B)(o|O)(u|U)(t|T)',
destination: '/about',
},
{
source: '/(s|S)ession',
destination: '/session',
},
{
source: '/(p|P)resenter',
destination: '/presenter',
},
];
},
images: {
domains: ['ddrt7tzfkdwdf.cloudfront.net', 'www.siliconvalley-codecamp.com'],
},
发布于 2021-08-10 20:11:51
next.config.js
中的rewrites
条目接受async
函数,该函数必须返回预期格式的对象数组。这意味着您可以向其中添加任何您想要的动态逻辑,甚至可以执行异步操作,如获取数据。
module.exports = {
async rewrites() {
// Add logic to generate dynamic rewrites array:
// Fetch data from external source, call functions, read files, etc
return dynamicRewritesArray;
}
};
https://stackoverflow.com/questions/68720503
复制相似问题