A modern full-stack React application combining TanStack Router with Hono for server-side rendering. This setup delivers fast, SEO-friendly applications with excellent developer experience.
- πΊ TanStack Router: Type-safe, file-based routing with powerful data loading
- β‘ Hono SSR: Ultra-fast server-side rendering with minimal overhead
- π₯ Vite: Lightning-fast development with Hot Module Replacement
- π TypeScript: Full type safety across client and server
- π¨ Tailwind CSS: Modern utility-first CSS framework
- π§Ή Biome: Fast linting, formatting, and code quality
- π§ͺ Vitest: Fast unit testing with great DX
src/
βββ components/
β βββ Header.tsx # Reusable UI components
βββ routes/ # File-based routing (auto-generated)
β βββ __root.tsx # Root layout component
β βββ index.tsx # Home page route
β βββ about.tsx # About page route
β βββ -test.ts # Test route utilities
βββ entry-client.tsx # Client-side hydration entry
βββ entry-server.tsx # Hono server with SSR setup
βββ router.tsx # Router configuration
βββ styles.css # Global styles
Start the development server:
npm install
npm run dev
This starts:
- Hono server with SSR at
http://localhost:3000
- Vite dev server with HMR for instant updates
- TanStack Router with file-based routing
Build and run for production:
# Build client and server bundles
npm run build
# Start production server
npm start
The build creates:
- Client bundle: Optimized assets with Vite manifest
- Server bundle: Hono server with embedded SSR
Run the test suite:
npm run test
Tailwind CSS for styling:
# Styles are processed through Vite with Tailwind
Biome for code quality:
npm run lint # Check for issues
npm run format # Format code
npm run check # Lint + format
- Request: Browser requests a URL
- Server: Hono matches route and runs TanStack Router SSR
- Render: React components render to HTML string
- Response: Full HTML sent to browser with embedded data
- Hydration: Client-side React takes over for SPA navigation
Routes are automatically generated from files in src/routes/
:
// src/routes/about.tsx
import { createFileRoute } from "@tanstack/react-router";
export const Route = createFileRoute("/about")({
component: AboutPage,
});
function AboutPage() {
return <div>About us!</div>;
}
Links work seamlessly between server and client:
import { Link } from "@tanstack/react-router";
<Link to="/about">About</Link>; // Works with SSR + client routing
Loaders run on the server and hydrate on the client:
export const Route = createFileRoute("/users")({
loader: async () => {
// Runs on server during SSR, then on client for navigation
const users = await fetch("/api/users").then((r) => r.json());
return { users };
},
component: UsersPage,
});
function UsersPage() {
const { users } = Route.useLoaderData();
return (
<ul>
{users.map((user) => (
<li key={user.id}>{user.name}</li>
))}
</ul>
);
}
The root layout (src/routes/__root.tsx
) wraps all pages:
import { Outlet, createRootRoute } from "@tanstack/react-router";
import { Header } from "../components/Header";
export const Route = createRootRoute({
component: RootLayout,
});
function RootLayout() {
return (
<>
<Header />
<main>
<Outlet /> {/* Child routes render here */}
</main>
</>
);
}
SSR Advantages:
- SEO: Fully rendered HTML for search engines
- LCP: Faster Largest Contentful Paint
- Progressive Enhancement: Works without JavaScript
- Social Sharing: Rich preview cards with meta tags
Hono Benefits:
- Small Bundle: Minimal server overhead
- Edge Ready: Deploy to Cloudflare Workers, etc.
- Fast Startup: Quick cold start times
Deploy to any Node.js hosting platform:
npm run build
NODE_ENV=production node dist/server.js
Popular platforms:
- Vercel/Netlify: Serverless functions
- Railway/Render: Container deployment
- Cloudflare Workers: Edge deployment with Hono
- Traditional VPS: PM2 + Nginx
- TanStack Router - Type-safe routing
- Hono - Ultrafast web framework
- SSR Guide - TanStack Router SSR
- Vite SSR - Vite server-side rendering