Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeScript Rollout Tier 17 - docs router #408

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export const afterEachGlobal = (vueApp, to, from) => {
import type { App } from 'vue'
import type { NavigationHookAfter } from 'vue-router'

export const afterEachGlobal = (vueApp: App, to: Parameters<NavigationHookAfter>[0]) => {
const title = to.meta.path === '/' ? to.meta.title : `${to.meta.title} | Buefy`
const url = `https://buefy.org${to.meta.path}`
const description = to.meta.subtitle.replace(/<(.|\n)*?>/g, '')
Expand All @@ -17,7 +20,7 @@ export const afterEachGlobal = (vueApp, to, from) => {

updates.forEach((item) => {
if (!item.value) return
document.querySelector(item.tag)
document.querySelector(item.tag)!
.setAttribute(item.attr || 'content', item.value)
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import type { App } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'
import { afterEachGlobal } from './guards.js'
import type { RouteComponent, RouteMeta } from 'vue-router'
import { afterEachGlobal } from './guards'
import routes from '@/data/routes'
import type { Route } from '@/data/routes'

export function createDocsRouter(vueApp) {
function route(path, component) {
declare module 'vue-router' {
interface RouteMeta extends Route {}
}

export function createDocsRouter(vueApp: App) {
function route(path: string, component: () => Promise<RouteComponent>) {
return {
path,
name: path,
meta: routes[path],
meta: routes[path] as RouteMeta,
// `component` is now a function to import the component; e.g.,
// () => import('@/pages/Home.vue')
//
Expand Down Expand Up @@ -95,11 +102,11 @@ export function createDocsRouter(vueApp) {
{
path: '/:pathMatch(.*)*',
name: 'notfound',
meta: routes.notfound,
meta: routes.notfound as RouteMeta,
component: NotFound
}
],
scrollBehavior(to, from, savedPosition) {
scrollBehavior(to) {
if (to.hash) {
return {
el: to.hash
Expand Down
Loading