Skip to content

Commit a50e064

Browse files
committed
feat: add exclude routes to app announcement
1 parent 4871be7 commit a50e064

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

playground/app.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default defineAppConfig({
1111
message: 'This is a site wide announcement!',
1212
buttonText: 'Click me',
1313
buttonUrl: 'https://nuxtify.dev/',
14+
exclude: ['/privacy', '/terms'],
1415
},
1516

1617
// Credits

playground/app.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ const clickToast = () => {
3737
<!-- Accessibility -->
3838
<NuxtRouteAnnouncer />
3939

40-
<AppAnnouncement
41-
v-if="nuxtifyConfig.announcement?.show"
42-
class="d-print-none"
43-
/>
40+
<AppAnnouncement />
4441

4542
<v-main>
4643
<v-container>

src/module.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export default defineNuxtModule<ModuleOptions>().with({
8383
message: '',
8484
buttonText: '',
8585
buttonUrl: '',
86+
exclude: [],
8687
},
8788

8889
// Navigation

src/runtime/components/app/AppAnnouncement.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
<script setup lang="ts">
2-
import { computed, isExternalUrl, useDisplay, useNuxtifyConfig } from '#imports'
2+
import { computed, isExternalUrl, useDisplay, useNuxtifyConfig, useRoute } from '#imports'
33
44
// App state
55
const nuxtifyConfig = useNuxtifyConfig()
66
const { xs } = useDisplay()
7+
const route = useRoute()
78
89
// Component state
910
const isExternalLink = computed(() =>
1011
isExternalUrl(nuxtifyConfig.announcement?.buttonUrl ?? '', nuxtifyConfig.brand?.domain ?? ''),
1112
)
13+
14+
const shouldShow = computed(() => {
15+
if (!nuxtifyConfig.announcement?.show) return false
16+
17+
const hasContent = nuxtifyConfig.announcement?.message || (nuxtifyConfig.announcement?.buttonText && nuxtifyConfig.announcement?.buttonUrl)
18+
if (!hasContent) return false
19+
20+
// Exclude routes
21+
const exclude: string[] = nuxtifyConfig.announcement?.exclude || []
22+
return !exclude.includes(route.path)
23+
})
1224
</script>
1325

1426
<template>
1527
<v-system-bar
28+
v-if="shouldShow"
1629
:height="xs ? 60 : 40"
1730
:order="-100"
18-
class="app-announcement justify-center text-start"
31+
class="app-announcement justify-center text-start d-print-none"
1932
>
2033
<div
2134
v-if="nuxtifyConfig.announcement?.message"

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export interface ModuleOptions {
9090
message?: string
9191
buttonText?: string
9292
buttonUrl?: string
93+
exclude?: string[]
9394
}
9495

9596
/**

0 commit comments

Comments
 (0)