Skip to content

Commit cb88068

Browse files
committed
fix: safely handle error for seo tags on bad routes
1 parent a37a7b4 commit cb88068

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

src/runtime/kit/head.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export type HeadContext = {
4848
getRouteBaseName: (route: RouteLocationResolvedGeneric | RouteLocationNormalizedLoadedGeneric) => string | undefined
4949
getLocaleRoute: (route: RouteLocationResolvedGeneric) => RouteLocationResolvedGeneric | undefined
5050
getCurrentRoute: () => RouteLocationNormalizedLoadedGeneric
51-
getRouteWithoutQuery: () => RouteLocationResolvedGeneric
51+
getRouteWithoutQuery: () => RouteLocationResolvedGeneric | undefined
5252
getLocalizedRoute: (locale: string, route: RouteLocationResolvedGeneric | undefined) => string
5353
}
5454

src/runtime/routing/head.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ function createHeadContext(
3636
getCurrentDirection: () => currentLocale.dir || __DEFAULT_DIRECTION__,
3737
getLocaleRoute: route => localeRoute(ctx, route),
3838
getLocalizedRoute: (locale, route) => switchLocalePath(ctx, locale, route),
39-
getRouteWithoutQuery: () =>
40-
assign({}, ctx.router.resolve({ query: {} }), { meta: ctx.router.currentRoute.value.meta })
39+
getRouteWithoutQuery: () => {
40+
try {
41+
return assign({}, ctx.router.resolve({ query: {} }), { meta: ctx.router.currentRoute.value.meta })
42+
} catch {
43+
return undefined
44+
}
45+
}
4146
}
4247
}
4348

0 commit comments

Comments
 (0)