Loading...
Loading...
Use when building or working with Vike + Vue SSR/SSG applications - establishes best practices for page creation, data fetching, routing, and layouts
npx skill4agent add yuann3/skills vike-skills+data+Page.vue+data.jsuseData()+guard.js+title+descriptionthrow render()throw redirect()clientOnly()+Page.vueuseData()export type Data = Awaited<ReturnType<typeof data>>throw render(404)<slot />+datathrow redirect('/login')throw render(401)<!-- /pages/movies/+Page.vue -->
<script setup lang="ts">
import { useData } from 'vike-vue/useData'
import type { Data } from './+data'
const { movies } = useData<Data>()
</script>
<template>
<h1>Movies</h1>
<ul>
<li v-for="movie in movies" :key="movie.id">
{{ movie.title }}
</li>
</ul>
</template>// /pages/movies/+data.ts
export type Data = Awaited<ReturnType<typeof data>>
export async function data() {
const movies = await fetchMovies()
return { movies }
}<!-- /pages/+Layout.vue -->
<script setup>
import Navigation from '../components/Navigation.vue'
</script>
<template>
<Navigation />
<main>
<slot />
</main>
</template>// /pages/admin/+guard.ts
import { redirect } from 'vike/abort'
export async function guard(pageContext) {
if (!pageContext.user) {
throw redirect('/login')
}
if (!pageContext.user.isAdmin) {
throw render(403, 'Admin access required')
}
}| File | Purpose |
|---|---|
| Page component |
| Layout wrapper |
| Server-side data fetching |
| Route protection |
| Page/directory configuration |
| Page title |
| Custom head tags |
| Suffix | Runs On |
|---|---|
| Server only (default for +data) |
| Client only |
| Both server and client |
windowdocumentclientOnly()passToClient+data+datathrow<slot />| Excuse | Reality |
|---|---|
| "I'll add SEO later" | Missing titles hurt from day one |
| "Guards can return false" | Guards must |
| "I can access window in +data" | |
| "pageContext has everything" | Use |
pages/
+config.ts # Applies to ALL pages
+Layout.vue # Global layout
(marketing)/
+Layout.vue # Nested inside global layout
about/+Page.vue # Has both layouts
admin/
+guard.ts # Applies to all admin pages
+config.ts # Admin-specific config
users/+Page.vue # Protected by guardpageContext.PagepageContext.datapageContext.configpageContext.routeParamspageContext.urlOriginalpageContext.urlPathnamepageContext.urlParseduser+config.tsexport default {
passToClient: ['user']
}Every Vike + Vue page must have:
1. +Page.vue component
2. +data.ts for server data (if needed)
3. useData() for type-safe data access
4. Error handling for edge cases
5. SEO tags for public pages