init: чистый старт Laravel + Vuexy
This commit is contained in:
36
resources/ts/plugins/1.router/index.ts
Normal file
36
resources/ts/plugins/1.router/index.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { setupLayouts } from 'virtual:meta-layouts'
|
||||
import type { App } from 'vue'
|
||||
|
||||
import type { RouteRecordRaw } from 'vue-router/auto'
|
||||
|
||||
import { createRouter, createWebHistory } from 'vue-router/auto'
|
||||
|
||||
function recursiveLayouts(route: RouteRecordRaw): RouteRecordRaw {
|
||||
if (route.children) {
|
||||
for (let i = 0; i < route.children.length; i++)
|
||||
route.children[i] = recursiveLayouts(route.children[i])
|
||||
|
||||
return route
|
||||
}
|
||||
|
||||
return setupLayouts([route])[0]
|
||||
}
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
scrollBehavior(to) {
|
||||
if (to.hash)
|
||||
return { el: to.hash, behavior: 'smooth', top: 60 }
|
||||
|
||||
return { top: 0 }
|
||||
},
|
||||
extendRoutes: pages => [
|
||||
...[...pages].map(route => recursiveLayouts(route)),
|
||||
],
|
||||
})
|
||||
|
||||
export { router }
|
||||
|
||||
export default function (app: App) {
|
||||
app.use(router)
|
||||
}
|
||||
Reference in New Issue
Block a user