Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
fix(karbon): page meta could be undefined when changing page
Browse files Browse the repository at this point in the history
  • Loading branch information
DanSnow committed Jun 7, 2023
1 parent 444f188 commit 03644af
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/karbon/src/runtime/composables/page-meta.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Ref } from 'vue'
import { useCurrentElement } from '@vueuse/core'
import { useCurrentElement, whenever } from '@vueuse/core'
import type { EventName } from '../api/track'
import type { UseArticleReturn as Article } from '../types'
import { useSEO } from './seo'
Expand Down Expand Up @@ -75,11 +75,17 @@ export function setupPage<Type extends PageType>({ type, seo = true }: SetupPage

if (type === 'article') {
const { $paywall } = useNuxtApp()
const { id, plan } = meta.value
onMounted(() => {
$paywall.mount()
$paywall.enable()
$paywall.setArticle({ id, plan })

whenever(
meta,
({ id, plan }) => {
$paywall.setArticle({ id, plan })
},
{ immediate: true, flush: 'sync' }
)
})
onBeforeUnmount(() => {
$paywall.disable()
Expand Down

0 comments on commit 03644af

Please sign in to comment.