Why Nuxt with Mizu?
Nuxt brings the best of Vue with additional superpowers: File-based routing - Create pages by adding files to thepages/ directory. Routes are automatically generated.
Auto-imports - Components, composables, and utilities are automatically imported. No more import statements!
Layouts - Define reusable page layouts that wrap your pages.
Composables - Vue’s Composition API with built-in composables like useFetch, useState, useRoute, and more.
Server Components - Write components that run on the server (or at build time) for better performance.
Developer Experience - Hot Module Replacement, TypeScript support, and excellent error messages.
Nuxt with Mizu vs Standalone Nuxt
| Feature | Nuxt + Mizu | Standalone Nuxt |
|---|---|---|
| Hosting | Single Go binary | Node.js server or Cloudflare |
| Backend | Go handlers | Nuxt server routes |
| Deployment | Any server with Go | Node.js required |
| SSR | ❌ No (SPA mode) | ✅ Yes |
| Static Generation | ✅ Yes (SPA) | ✅ Yes (SSG) |
| API Routes | Go backend | Nuxt server routes |
| Performance | ⚡ Very fast (Go) | ⚡ Fast (Node.js) |
| Type Safety | Backend: Go, Frontend: TS | Full-stack TypeScript |
- You want Nuxt’s DX (auto-imports, composables, file-based routing)
- You prefer Go for backend APIs
- You want a single binary deployment
- You’re building an SPA or static site
- You need full SSR (server-side rendering at request time)
- You want Nuxt server routes and middleware
- You prefer Node.js for everything
- You need Nuxt’s full-stack features (server components, API routes)
Nuxt vs Vue with Vite
| Feature | Nuxt | Vue + Vite |
|---|---|---|
| File-based routing | ✅ Built-in | ⚠️ Manual (vue-router) |
| Auto-imports | ✅ Yes | ❌ No |
| Layouts | ✅ Built-in | ⚠️ Manual |
| Built-in composables | ✅ Many | ⚠️ Few |
| Bundle size | ⚠️ Larger | ✅ Smaller |
| Setup complexity | ⚠️ More | ✅ Less |
| Flexibility | ⚠️ Opinionated | ✅ Very flexible |
| Best for | Apps, sites | Libraries, simple apps |
How Nuxt Works with Mizu
When you build Nuxt in SPA mode for Mizu:- Mizu serves the pre-built files
- Browser loads
index.html+ JavaScript - Vue takes over and renders the app
- Client-side routing handles navigation
- API calls go to Mizu backend (Go)
Quick Start
Create a new Nuxt project with the CLI:http://localhost:3000 to see your app!
Project Structure
Configuration
Nuxt Configuration
Configure Nuxt for SPA mode and Mizu integration:frontend/nuxt.config.ts
- ssr: false - Runs Nuxt in SPA mode (no server-side rendering)
- nitro.output - Outputs built files to
dist/directory - vite.server.hmr.clientPort - HMR through Mizu’s proxy on port 3000
- components.dirs - Directories to auto-import components from
Backend Configuration
app/server/app.go
app/server/routes.go
File-Based Routing
Nuxt automatically generates routes based on files in thepages/ directory.
Basic Routes
Nested Routes
Dynamic Routes
Use square brackets for dynamic segments:Route Parameters
Access route parameters withuseRoute():
pages/users/[id].vue
Catch-All Routes
Create a catch-all route with[...slug].vue:
Auto-Imports
One of Nuxt’s killer features is auto-imports. No more import statements!What Gets Auto-Imported?
Vue APIs:Auto-Import Configuration
Control what gets auto-imported innuxt.config.ts:
TypeScript Support
Nuxt automatically generates TypeScript types for auto-imports:Layouts
Layouts wrap your pages with common UI elements.Default Layout
Create a default layout that wraps all pages:layouts/default.vue
Custom Layouts
Create additional layouts for different page types:layouts/auth.vue
Using Layouts in Pages
Specify which layout to use withdefinePageMeta:
No Layout
Disable layout for a page:Built-in Composables
Nuxt provides powerful composables for common tasks.useFetch
Fetch data from an API:useAsyncData
More control over async data fetching:useState
Shared state across components:useRoute and useRouter
Access routing information:useCookie
Work with cookies:useHead
Manage document head:Custom Composables
Create reusable composables for your app logic:User Management Composable
Authentication Composable
Middleware
Route middleware runs before rendering a page.Global Middleware
Runs on every route:Named Middleware
Runs only when specified:Multiple Middleware
Components
Auto-Imported Components
Components incomponents/ are automatically available:
Component Example
State Management with Pinia
For complex state, use Pinia:nuxt.config.ts:
Styling
Scoped Styles
Use scoped styles by default:Global Styles
Create global CSS:nuxt.config.ts:
Tailwind CSS
Install Tailwind module:nuxt.config.ts:
CSS Modules
Plugins
Create Vue plugins:Development Workflow
Starting Development
- Nuxt runs dev server on port 5173
- Mizu runs on port 3000
- Requests to port 3000 proxy to Nuxt (except
/api) - Visit
http://localhost:3000 - HMR works through proxy
Making Changes
Frontend changes:- Edit files in
frontend/ - Nuxt HMR updates browser instantly
- Components, pages, composables auto-reload
- Edit Go files
- Restart Mizu server
- Or use
airfor auto-reload
Building for Production
Build the application:cd frontend && npm run build- Nuxt buildgo build- Go binary with embedded frontend
Build Output
Running in Production
TypeScript
Nuxt has excellent TypeScript support:Typed Composables
Typed Components
Auto-Generated Types
Nuxt generates types automatically:Troubleshooting
HMR Not Working
Symptom: Changes don’t appear in browser Cause: HMR WebSocket not connecting through proxy Solution: Checkvite.server.hmr.clientPort in nuxt.config.ts:
Hydration Mismatch
Error:<ClientOnly>:
Auto-Import Not Working
Symptom: Component/composable not found Solution 1: Check file naming (must be in correct directory).nuxt/ was generated:
404 on Refresh in SPA Mode
Symptom: Page works initially, but refreshing gives 404 Cause: SPA fallback not configured Solution: Mizu automatically handles this, but ensure:Build Fails: “Cannot find module”
Error:tsconfig.json: