Discover how to keep your code neat and URLs clean without compromise!
Why Route groups with (groupName) in NextJS? - Purpose & Use Cases
Imagine building a website with many pages and trying to organize them by folders manually, but you want some pages grouped logically without changing their URL paths.
Manually managing folders for routes can clutter URLs or force awkward folder structures, making it hard to keep code clean and URLs user-friendly.
Route groups with (groupName) let you group pages in the file system for better code organization without affecting the URL structure, keeping URLs clean and code tidy.
app/dashboard/settings/page.tsx // URL: /dashboard/settings app/dashboard/profile/page.tsx // URL: /dashboard/profile
app/dashboard/(admin)/settings/page.tsx // URL: /dashboard/settings app/dashboard/(admin)/profile/page.tsx // URL: /dashboard/profile
This lets you organize your app's code clearly while keeping URLs simple and user-friendly.
Think of an online store where admin pages are grouped in code but don't show extra folder names in the URL, making links neat and easy to share.
Manual folder structure can clutter URLs and code.
Route groups organize code without changing URLs.
Clean URLs and tidy code make development easier and user experience better.