Performance: Conditional routes
MEDIUM IMPACT
Conditional routes affect page load speed and interaction responsiveness by controlling which pages or components load based on conditions.
import dynamic from 'next/dynamic'; const Dashboard = dynamic(() => import('./Dashboard')); const Login = dynamic(() => import('./Login')); export default function Page() { if (user.isLoggedIn) { return <Dashboard />; } else { return <Login />; } }
export default function Page() { if (user.isLoggedIn) { return <Dashboard />; } else { return <Login />; } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Static import of all routes | Low to medium (depends on components) | 1 per route render | Medium due to larger bundle | [X] Bad |
| Dynamic import with conditional rendering | Low (only needed components) | 1 per route render | Low due to smaller bundle | [OK] Good |