Company
Date Published
Author
Lee Robinson
Word count
708
Language
English
Hacker News points
None

Summary

The Next.js team has released a new feature called layouts, which allows developers to create nestable layouts that can be shared across pages, enabling a more modular and maintainable routing system. The new layout system uses a file-based approach, where each route segment is mapped to a corresponding segment in a URL path, allowing for incremental adoption of the app directory from the existing pages directory. Developers can create custom layouts for specific route segments using layout.js files, which can be shared across different pages, and even used to isolate errors to specific parts of an app. The new system also includes loading and error boundaries, such as loading.js and error.js, which provide a React Suspense boundary and React Error Boundary respectively, allowing for meaningful loading UI and error handling. Additionally, route groups can be used to organize routes without affecting the URL path, optimize segments out of layouts, or create multiple root layouts for sections of an app with different UI.