Category: Next.js, React and TypeScript

Next.js Link: href is required when rendering the list

Read this guide in Polish

The list of guides works for some of the records, but the render of one item with Link ends up with an error of missing href. The data may have an empty service or the URL builder function received undefined from an optional field.

How to identify the source of the problem

Check the href values for each item before being transferred to Link component. Determine whether the data source contains work records without service that should not be published.

Compare the message from the console with the result of the production compilation and the condition after the page has been refreshed.

Repair steps

Validate service when importing content and generate Link only for existing, valid addresses. For missing data, show a non-critical condition and save a validation error in CI instead of creating /undefined.

How to Test Solution

Each link is correct and leads to an existing address; the directory does not render random service.

Security and restrictions

Do not hide the enter error with the count="#" for each broken record.