handle storing route config
This commit is contained in:
parent
dca70d7028
commit
6e4be6ca3e
6 changed files with 57 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -11,6 +11,7 @@ node_modules
|
||||||
dist
|
dist
|
||||||
dist-ssr
|
dist-ssr
|
||||||
*.local
|
*.local
|
||||||
|
.vite-ssg-temp
|
||||||
/content
|
/content
|
||||||
|
|
||||||
# Editor directories and files
|
# Editor directories and files
|
||||||
|
|
8
src/content-env.d.ts
vendored
8
src/content-env.d.ts
vendored
|
@ -2,10 +2,12 @@ declare module 'content/routes.js' {
|
||||||
type Template =
|
type Template =
|
||||||
| 'markdown'
|
| 'markdown'
|
||||||
|
|
||||||
type Routes = { [key: string]: {
|
type RouteDefinition = {
|
||||||
id: string
|
id: string
|
||||||
template: Template
|
template: Template
|
||||||
}}
|
}
|
||||||
|
|
||||||
const routes: Routes
|
type RouteCollection = { [key: string]: RouteDefinition }
|
||||||
|
|
||||||
|
const routes: RouteCollection
|
||||||
}
|
}
|
||||||
|
|
18
src/main.ts
18
src/main.ts
|
@ -1,7 +1,10 @@
|
||||||
|
import { type RouteRecordRaw } from 'vue-router'
|
||||||
import { ViteSSG } from 'vite-ssg'
|
import { ViteSSG } from 'vite-ssg'
|
||||||
import './style.css'
|
import './style.css'
|
||||||
import main from './main.vue'
|
import main from './main.vue'
|
||||||
import { createRoutes } from './routes'
|
import { createPinia } from 'pinia'
|
||||||
|
import { createRoutes, useRouteStore } from './routes'
|
||||||
|
import { routes as appRoutes, type RouteDefinition } from 'content/routes.js'
|
||||||
|
|
||||||
export const createApp = ViteSSG(
|
export const createApp = ViteSSG(
|
||||||
// the root component
|
// the root component
|
||||||
|
@ -9,7 +12,14 @@ export const createApp = ViteSSG(
|
||||||
// vue-router options
|
// vue-router options
|
||||||
{ routes: createRoutes() },
|
{ routes: createRoutes() },
|
||||||
// function to have custom setups
|
// function to have custom setups
|
||||||
// ({ app, router, routes, isClient, initialState }) => {
|
({ app, router, routes, isClient, initialState }) => {
|
||||||
// // install plugins etc.
|
app.use(createPinia())
|
||||||
// },
|
const routeStore = useRouteStore()
|
||||||
|
Object.keys(appRoutes).forEach(route =>
|
||||||
|
routeStore._routes[route] = {
|
||||||
|
...routes.find(other => other.path === route) as RouteRecordRaw,
|
||||||
|
...appRoutes[route] as RouteDefinition,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
|
import { defineStore } from 'pinia'
|
||||||
import { type RouteRecordRaw } from 'vue-router'
|
import { type RouteRecordRaw } from 'vue-router'
|
||||||
import { routes, type Template } from 'content/routes.js'
|
import { routes, type RouteDefinition, type Template } from 'content/routes.js'
|
||||||
|
|
||||||
const markdownBody = () => import ('./views/markdown.vue')
|
const markdownBody = () => import ('./views/markdown.vue')
|
||||||
|
|
||||||
|
@ -20,3 +21,18 @@ export const createRoutes = (): RouteRecordRaw[] => {
|
||||||
|
|
||||||
return routeRecord
|
return routeRecord
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const useRouteStore = defineStore('routeStore', {
|
||||||
|
state: () => ({
|
||||||
|
_routes: {} as Record<string, RouteRecordRaw & RouteDefinition>,
|
||||||
|
}),
|
||||||
|
actions: {
|
||||||
|
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export type RouteStoreDefinition = Omit<
|
||||||
|
ReturnType<typeof useRouteStore>,
|
||||||
|
keyof ReturnType<typeof defineStore>
|
||||||
|
>
|
||||||
|
|
||||||
|
|
18
src/views/markdown.vue
Normal file
18
src/views/markdown.vue
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useRoute } from 'vue-router'
|
||||||
|
import { useRouteStore } from 'src/routes'
|
||||||
|
|
||||||
|
const currentRoute = useRoute()
|
||||||
|
const routeStore = useRouteStore()
|
||||||
|
|
||||||
|
console.log(routeStore._routes)
|
||||||
|
console.log(routeStore._routes[currentRoute.path])
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template lang="pug">
|
||||||
|
p Marked works
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped lang="sass">
|
||||||
|
|
||||||
|
</style>
|
|
@ -22,8 +22,8 @@
|
||||||
|
|
||||||
/* Linting */
|
/* Linting */
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"noUnusedLocals": true,
|
"noUnusedLocals": false,
|
||||||
"noUnusedParameters": true,
|
"noUnusedParameters": false,
|
||||||
"noFallthroughCasesInSwitch": true
|
"noFallthroughCasesInSwitch": true
|
||||||
},
|
},
|
||||||
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
|
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"],
|
||||||
|
|
Loading…
Add table
Reference in a new issue