如果我通过url(浏览器地址栏)更改语言,则nextjs-i18next返回404

时间:2020-11-04 17:13:45

标签: next.js i18next react-i18next next-i18next

我已经在我的本地主机中部署了我的nextjs项目,并且如果我在浏览器URL栏中手动从“ /”根目录(英语)和“ / de”(德语)更改语言,则此方法可以正常工作。如果我使用切换器按钮,也可以正常工作。 但是,当我将其作为无服务器组件部署到AWS Cloudfront中的服务器时,如果我使用切换器按钮更改语言,但如果我从默认lang“英语”“ /”(如果更改)返回“ 404页面未找到”,也可以正常工作。 root)更改为语言“ / es”。 请帮忙吗?怎么了? 我的测试网址是:http://test.nootric.com

谢谢!

这是我的i18n.js文件:

const NextI18Next = require('next-i18next').default
const { localeSubpaths } = require('next/config').default().publicRuntimeConfig
const path = require('path') 

module.exports = new NextI18Next({
    strictMode: false, 
    defaultLanguage: 'en',
    serverLanguageDetection: false, // <---
    otherLanguages: ['es'],
    ignoreRoutes: ['/public/', '/api/', '/auth/', '/purchase/', '/settings/'],
    localeSubpaths,
    localePath: path.resolve('./public/locales')
})

这是我的next.config.js:

const withSass = require("@zeit/next-sass");
const { nextI18NextRewrites } = require('next-i18next/rewrites');

const localeLanguages = [
     { label: 'en', name: 'English' },
     { label: 'es', name: 'Español' }     
];
const localeSubpaths = {  
     es: 'es',
};
// Extend your Next config for advanced behavior
// See https://nextjs.org/docs/api-reference/next.config.js/introduction
let nextConfig = {
     rewrites: async () => nextI18NextRewrites(localeSubpaths),
     publicRuntimeConfig: {
          localeLanguages, 
          localeSubpaths
     },
};

// Add the Next SASS plugin
nextConfig = withSass(nextConfig);

module.exports = nextConfig;

0 个答案:

没有答案