I have an edit page that will be rendered with an id parameter and it works fine when application is running but while building the nextjs app I get this error the full errorI am not sure what this error is related to or what mistake am I making in my code that this error is occuring during build time.Here is the code of my pageimport { WithAuthorization } from 'common/roq-hocs';import { MainLayout } from 'layouts';import { useTranslation } from 'next-i18next';import { serverSideTranslations } from 'next-i18next/serverSideTranslations';import React, { FunctionComponent } from 'react';import { CompaniesEditView } from 'views/companies-edit';const CompanyCreatePage: FunctionComponent = () => { const { t } = useTranslation('companiesEdit'); return ( <MainLayout title={t('title')}> <WithAuthorization permissionKey="companies.update" failComponent={ <div className="mt-16 text-2xl text-center text-gray-600"> <span>{t('noView')}</span> </div> } > <CompaniesEditView /> </WithAuthorization> </MainLayout> );};export const getStaticProps = async ({ locale }) => ({ props: { ...(await serverSideTranslations(locale, ['common', 'companiesEdit'])), },});export const getStaticPaths = () => ({ paths: ['/companies/edit/[id]'], fallback: true,});export default CompanyCreatePage; 解决方案 I think that the problem might be that you are not returning the expected paths model in getStaticPaths function.Minimal example of this page:import { GetStaticPaths, GetStaticProps } from 'next';import { useRouter } from 'next/router';const CompanyCreatePage = () => { const router = useRouter(); const { id } = router.query; return ( <div> <h1>Company Create Page Content for id: {id}</h1> </div> );};export const getStaticPaths: GetStaticPaths = async () => { // Get all possible 'id' values via API, file, etc. const ids = ['1', '2', '3', '4', '5']; // Example const paths = ids.map(id => ({ params: { id }, })); return { paths, fallback: false };};export const getStaticProps: GetStaticProps = async context => { return { props: {} };};export default CompanyCreatePage;Then, navigating to the page /users/edit/3/ returns the following contentTake into account that the fallback param in getStaticPaths changes the behavior of getStaticProps function. For reference, see the documentation 这篇关于Nextjs 动态路由与 next-i18next 构建错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-19 09:42