{
  "version": "https://jsonfeed.org/version/1",
  "title": "Nextjs on LLBBL Blog",
  "icon": "https://avatars.micro.blog/avatars/2023/40/125738.jpg",
  "home_page_url": "https://llbbl.blog/",
  "feed_url": "https://llbbl.blog/feed.json",
  "items": [
      {
        "id": "http://llbbl.micro.blog/2026/04/10/routing-in-sveltekit-vs-nextjs.html",
        "title": "Routing in SvelteKit vs Next.js vs Astro",
        "content_html": "<p>Continuing my series on Svelte, I want to dig into how SvelteKit handles routing and how it compares with Next.js and Astro. These are the frameworks I am most familiar with, so apologies if you wanted a different framework.</p>\n<p>Let&rsquo;s start with everybody&rsquo;s favorite topic: routing. Okay, maybe I&rsquo;m the only one excited about this, but stick with me.</p>\n<h2 id=\"astro-the-traditional-approach\">Astro: The Traditional Approach</h2>\n<p>Astro&rsquo;s routing feels the most traditional of the three. You have a <code>src/pages/</code> directory, and the file name <em>is</em> the route. So <code>src/pages/dashboard.astro</code> maps to <code>/dashboard</code>. If you&rsquo;ve worked with PHP or other languages with file-based routing, this will feel immediately familiar.</p>\n<p>Inside the <code>.astro</code> file, you separate your backend logic at the top of the file with <code>---</code> fences. That code runs entirely on the server, and everything below is your HTML template. Clean and straightforward.</p>\n<h2 id=\"nextjs-folder-based-with-the-app-router\">Next.js: Folder-Based with the App Router</h2>\n<p>Next.js (the current versions, at least) uses the App Router. The structure is folder-based: <code>app/dashboard/page.tsx</code> maps to <code>/dashboard</code>. The key difference from Astro is that the <em>folder</em> name determines the route, but the file must always be called <code>page.tsx</code>.</p>\n<p>By default, everything in the <code>app</code> directory is a server component, meaning it runs on the server. If you want client-side interactivity, you explicitly add <code>&quot;use client&quot;</code> at the top of the file. You can also set <code>&quot;use server&quot;</code> if you want to be explicit, but it&rsquo;s the default. I think Next.js does a really good job of making it clear what runs where.</p>\n<h2 id=\"sveltekit-convention-over-configuration\">SvelteKit: Convention Over Configuration</h2>\n<p>SvelteKit also uses folder-based routing, similar to Next.js. The structure is <code>src/routes/dashboard/</code>, but instead of <code>page.tsx</code>, SvelteKit uses a reserved <code>+</code> prefix for its special files:</p>\n<ul>\n<li><strong><code>+page.svelte</code></strong> — Renders on the server, then hydrates on the client</li>\n<li><strong><code>+page.server.ts</code></strong> — Runs <em>only</em> on the server (data loading, form actions)</li>\n<li><strong><code>+server.ts</code></strong> — A raw API endpoint with no UI</li>\n</ul>\n<p>There&rsquo;s no <code>&quot;use client&quot;</code> or <code>&quot;use server&quot;</code> directive. The file naming convention itself tells SvelteKit what should run where. If you fetch a database record in <code>+page.server.ts</code>, that data is returned as an object, fully typed, and available in your <code>+page.svelte</code> via the <code>$props</code> rune. It just works.</p>\n<h2 id=\"the-case-for-standard-file-names\">The Case for Standard File Names</h2>\n<p>I can see if some people get annoyed that every route has files named <code>+page.svelte</code> and <code>+page.server.ts</code>. The files will all look the same in the IDE, but there&rsquo;s a real advantage here: you can group all related components in the same route folder.</p>\n<p>For example, if you&rsquo;re building a dashboard, you can keep your <code>DashboardChart.svelte</code>, <code>DashboardFilters.svelte</code>, and other components right alongside your <code>+page.svelte</code> and <code>+page.server.ts</code>. You always know which file is the route entry point, which handles server logic, and which are supporting components. It encourages logical grouping instead of scattering related files across the project.</p>\n<h2 id=\"quick-comparison\">Quick Comparison</h2>\n<table>\n<thead>\n<tr>\n<th>Feature</th>\n<th>Astro</th>\n<th>Next.js</th>\n<th>SvelteKit</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Route structure</td>\n<td>File name = route</td>\n<td>Folder + <code>page.tsx</code></td>\n<td>Folder + <code>+page.svelte</code></td>\n</tr>\n<tr>\n<td>Server/client split</td>\n<td><code>---</code> fences</td>\n<td><code>&quot;use client&quot;</code> directive</td>\n<td>File naming convention</td>\n</tr>\n<tr>\n<td>API routes</td>\n<td><code>src/pages/api/</code></td>\n<td><code>app/api/route.ts</code></td>\n<td><code>+server.ts</code></td>\n</tr>\n<tr>\n<td>Default rendering</td>\n<td>Server</td>\n<td>Server</td>\n<td>Server + hydration</td>\n</tr>\n</tbody>\n</table>\n<p>All three frameworks use file-based routing, but they each have a slightly different philosophy about how to organize and separate concerns. Astro keeps it simple with traditional file mapping. Next.js gives you explicit directives. SvelteKit leans on naming conventions to keep things clean.</p>\n<p>I think I can get used to the <code>+</code> prefix convention in SvelteKit. The type safety between your server file and your page component is nice.</p>\n<p>Next up in the series, I&rsquo;ll dig into how each framework handles data loading and forms.</p>\n",
        "date_published": "2026-04-10T10:00:00-05:00",
        "url": "https://llbbl.blog/2026/04/10/routing-in-sveltekit-vs-nextjs.html",
        "tags": ["Astro","svelte","Web development","Sveltekit","Nextjs"]
      }
  ]
}
