0

While usign the getStaticPaths() and getStaticProps() I am getting the error NextJS: "TypeError: Cannot read property 'toLowerCase' of undefined"

4

1 回答 1

0

The problem was in getStaticPaths() I was directly returning an array of strings as paths:

Wrong Code

export const getStaticPaths = async () => {    
 ...

    return {
      paths: ['product1','product2','product3'], //WRONG
      fallback: 'blocking'
    }
}

The solution was to return the paths array in a diffent structure:

Correct Code

export const getStaticPaths = async () => {    
 ...

    return {
      paths: [
          {'params': {myPageSlug: 'product1'}},
          {'params': {myPageSlug: 'product2'}},
          {'params': {myPageSlug: 'product3'}},
      ], //OK
      fallback: 'blocking'
    }
}

myPageSlug is the slug used when naming the page file, example: pages/[myPageSlug].tsx

于 2020-12-03T14:49:14.040 回答