Skip to content

Commit

Permalink
chore: add simpler example with unplugin-vue-router
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCampionJr committed Dec 16, 2023
1 parent 5542aa7 commit cae7638
Show file tree
Hide file tree
Showing 27 changed files with 435 additions and 0 deletions.
12 changes: 12 additions & 0 deletions examples/unplugin-vue-router/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
24 changes: 24 additions & 0 deletions examples/unplugin-vue-router/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"private": true,
"scripts": {
"dev": "nodemon --watch ../../dist/index.js -x \"cross-env DEBUG=vite-plugin-layouts vite\"",
"build": "cross-env DEBUG=vite-plugin-layouts vite build",
"serve": "vite preview"
},
"dependencies": {
"vue": "^3.3.10"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.5.0",
"@vue/compiler-sfc": "^3.3.8",
"cross-env": "^7.0.3",
"nodemon": "^3.0.1",
"typescript": "^5.3.2",
"vite": "^5.0.2",
"vite-plugin-inspect": "^0.8.1",
"vite-plugin-pages": "^0.32.0",
"vite-plugin-vue-layouts": "workspace:*",
"unplugin-vue-markdown": "^0.25.2",
"unplugin-vue-router": "^0.7.0"
}
}
3 changes: 3 additions & 0 deletions examples/unplugin-vue-router/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<router-view />
</template>
1 change: 1 addition & 0 deletions examples/unplugin-vue-router/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.test { }
8 changes: 8 additions & 0 deletions examples/unplugin-vue-router/src/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template>
<main class="px-4 py-10 text-center text-gray-700 dark:text-gray-200">
<div class="w-1/4 m-auto text-center text-gray-300 bg-teal-800">
Default Layout
</div>
<router-view />
</main>
</template>
8 changes: 8 additions & 0 deletions examples/unplugin-vue-router/src/layouts/second.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template>
<main class="px-4 py-10 text-center text-gray-700 dark:text-gray-200">
<div class="w-1/4 m-auto text-center text-gray-300 bg-teal-800">
Second Layout
</div>
<router-view />
</main>
</template>
8 changes: 8 additions & 0 deletions examples/unplugin-vue-router/src/layouts/sub/layoutsub.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template>
<main class="px-4 py-10 text-center text-gray-700 dark:text-gray-200">
<div class="w-1/4 m-auto text-center text-gray-300 bg-teal-800">
Layout Sub Folder
</div>
<router-view />
</main>
</template>
19 changes: 19 additions & 0 deletions examples/unplugin-vue-router/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { createApp } from 'vue'
import { createRouter, createWebHistory } from 'vue-router/auto'
import { createGetRoutes, setupLayouts } from 'virtual:generated-layouts'
import App from './App.vue'
import './index.css'

const router = createRouter({
history: createWebHistory(),
extendRoutes: routes => setupLayouts(routes),
})

const getRoutes = createGetRoutes(router)
console.log(getRoutes())

const app = createApp(App)

app.use(router)

app.mount('#app')
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template>
<main class="px-4 py-10 text-center text-gray-700 dark:text-gray-200">
<div class="w-1/4 m-auto text-center text-gray-300 bg-teal-800">
Module 1 Layout
</div>
<router-view />
</main>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template>
<main class="px-4 py-10 text-center text-gray-700 dark:text-gray-200">
<div class="w-1/4 m-auto text-center text-gray-300 bg-teal-800">
Module 2 Layout
</div>
<router-view />
</main>
</template>
6 changes: 6 additions & 0 deletions examples/unplugin-vue-router/src/pages/about/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<p>/about/index.vue</p>
<router-link to="/about/who/me">
me
</router-link>
</template>
12 changes: 12 additions & 0 deletions examples/unplugin-vue-router/src/pages/about/who/me.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<p>meeeeee</p>
</template>

<route>
{
name: "who-me-override",
meta: {
requiresAuth: false
}
}
</route>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div>Deepest Sub folder page with no layout set, should use default</div>
</template>
6 changes: 6 additions & 0 deletions examples/unplugin-vue-router/src/pages/deep/deeper/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<div>
Deeper Sub folder page with no layout set, should use default
<p><router-link to="/deep/deeper/deepest">Go Deepest</router-link></p>
</div>
</template>
6 changes: 6 additions & 0 deletions examples/unplugin-vue-router/src/pages/deep/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<template>
<div>
Sub folder page with no layout set, should use default
<p><router-link to="/deep/deeper">Go Deeper</router-link></p>
</div>
</template>
39 changes: 39 additions & 0 deletions examples/unplugin-vue-router/src/pages/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<template>
<div>
<p>index.vue</p>
<router-link to="/about"> about </router-link>
<p>
<router-link to="/news"> news </router-link> |
<router-link :to="{ name: 'named-news-page' }">
today's news
</router-link>
</p>
<p>
<router-link to="/sublayout"> sub layout </router-link>
</p>
<p>
<router-link to="/nolayout"> no layout </router-link>
</p>
<p>
<router-link to="/module1"> module 1 layout </router-link>
</p>
<p>
<router-link to="/module2"> module 2 layout </router-link>
</p>
<p>
<router-link to="/second"> second level layout </router-link>
</p>
<p>
<router-link to="/deep">
deep sub folder with no layout specified
</router-link>
</p>
</div>
</template>

<route>
{
name: "name-override",
meta: {requiresAuth: false}
}
</route>
10 changes: 10 additions & 0 deletions examples/unplugin-vue-router/src/pages/module1.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<div>Module 1 Content</div>
</template>
<route>
{
meta: {
layout: "module1layout"
}
}
</route>
10 changes: 10 additions & 0 deletions examples/unplugin-vue-router/src/pages/module2.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<div>Module 2 Content</div>
</template>
<route>
{
meta: {
layout: "module2layout"
}
}
</route>
10 changes: 10 additions & 0 deletions examples/unplugin-vue-router/src/pages/news.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<router-view />
</template>
<route>
{
meta: {
layout: "second"
}
}
</route>
8 changes: 8 additions & 0 deletions examples/unplugin-vue-router/src/pages/news/Today.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template>
<p>/news/today.vue</p>
</template>
<route>
{
name: 'named-news-page'
}
</route>
3 changes: 3 additions & 0 deletions examples/unplugin-vue-router/src/pages/news/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<p>/news/index.vue</p>
</template>
10 changes: 10 additions & 0 deletions examples/unplugin-vue-router/src/pages/nolayout.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<div>
<p>nolayout</p>
</div>
</template>

<route lang="yaml">
meta:
layout: false
</route>
13 changes: 13 additions & 0 deletions examples/unplugin-vue-router/src/pages/second/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<div>
Second level layout.
<router-view />
</div>
</template>
<route>
{
meta: {
layout: "second"
}
}
</route>
12 changes: 12 additions & 0 deletions examples/unplugin-vue-router/src/pages/sublayout.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<div>
<p>sublayout</p>
</div>
</template>

<route>
{meta: {
layout: "sub/layoutsub"
}
}
</route>
5 changes: 5 additions & 0 deletions examples/unplugin-vue-router/src/shims-vue.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
declare module '*.vue' {
import type { DefineComponent } from 'vue'
const component: DefineComponent<{}, {}, any>
export default component
}
Loading

0 comments on commit cae7638

Please sign in to comment.