Skip to content

TIL - Next.js Project Organization

Posted on:October 19, 2023 at 07:33 AM

Project Organization Features for App Router

Private, route groups, src

Module path aliases

// before
import { Button } from '../../../components/button'
 
// after
import { Button } from '@/components/button'

Absolute Imports

{
  "compilerOptions": {
    "baseUrl": "./app"
  }
}

Doing this enables you to import Button that is located in the component folder of your root directory as:

import Button from 'components/button'

You can additionally set up “alias” module paths (‘alias’ - which literally means another name that you go by) by using "paths" option.

{
  "compilerOptions": {
   "baseUrl": "./app"
    "paths": {
      "@/*": ["./*"]
    }
  }
}