GitHub

File tree

  • docs/content/docs/1.getting-started/2.installation

  • src

    • plugins

    • runtime/vue

      • overrides/none

      • plugins

Original file line numberDiff line numberDiff line change

@@ -737,6 +737,27 @@ export default defineConfig({

737737

})

738738

```

739739
740+

::tip

741+

You can provide custom navigation logic for frameworks like **Hybridly** by setting `router: false` in the Vite config and passing a function when installing the Vue plugin:

742+
743+

```ts [main.ts]

744+

import ui from '@nuxt/ui/vue-plugin'

745+

import { router } from 'hybridly'

746+
747+

app.use(ui, {

748+

router: (event, { href, external }) => {

749+

if (external) {

750+

return

751+

}

752+
753+

event.preventDefault()

754+
755+

router.navigate({ url: href })

756+

}

757+

})

758+

```

759+

::

760+
740761

::note

741762

When set to `false` or `'inertia'`, `vue-router` is not required as a dependency.

742763

::

Original file line numberDiff line numberDiff line change

@@ -14,7 +14,9 @@ import type { NuxtUIOptions } from '../unplugin'

1414

export default function PluginsPlugin(options: NuxtUIOptions) {

1515

const plugins = globSync(['**/*', '!*.d.ts'], { cwd: join(runtimeDir, 'plugins'), absolute: true })

1616
17+

plugins.unshift(resolvePathSync('../runtime/vue/plugins/router', { extensions: ['.ts', '.mjs', '.js'], url: import.meta.url }))

1718

plugins.unshift(resolvePathSync('../runtime/vue/plugins/head', { extensions: ['.ts', '.mjs', '.js'], url: import.meta.url }))

19+
1820

if (options.colorMode) {

1921

plugins.push(resolvePathSync('../runtime/vue/plugins/color-mode', { extensions: ['.ts', '.mjs', '.js'], url: import.meta.url }))

2022

}

@@ -44,9 +46,10 @@ export default function PluginsPlugin(options: NuxtUIOptions) {

4446

load() {

4547

return `

4648

${plugins.map(p => `import ${genSafeVariableName(p)} from "${p}"`).join('\n')}

49+
4750

export default {

48-

install (app) {

49-

${plugins.map(p => ` app.use(${genSafeVariableName(p)})`).join('\n')}

51+

install (app, pluginOptions = {}) {

52+

${plugins.map(p => ` app.use(${genSafeVariableName(p)}, pluginOptions)`).join('\n')}

5053

}

5154

}

5255

`

Original file line numberDiff line numberDiff line change

@@ -71,7 +71,7 @@ export interface LinkSlots {

7171

</script>

7272
7373

<script setup lang="ts">

74-

import { computed } from 'vue'

74+

import { computed, inject } from 'vue'

7575

import { defu } from 'defu'

7676

import { hasProtocol } from 'ufo'

7777

import { useAppConfig } from '#imports'

@@ -154,6 +154,18 @@ const linkRel = computed(() => {

154154
155155

return null

156156

})

157+
158+

const handleNavigation = inject<((event: MouseEvent, context: { href: string, external: boolean, target?: string | null }) => void) | undefined>('nuxtui:router', undefined)

159+
160+

const navigate = handleNavigation

161+

? (e: MouseEvent) => {

162+

handleNavigation(e, {

163+

href: href.value || '',

164+

external: isExternal.value,

165+

target: props.target || (isExternal.value ? '_blank' : undefined)

166+

})

167+

}

168+

: undefined

157169

</script>

158170
159171

<template>

@@ -164,8 +176,8 @@ const linkRel = computed(() => {

164176

as,

165177

type,

166178

disabled,

167-

href: href,

168-

navigate: undefined,

179+

href,

180+

navigate,

169181

rel: linkRel,

170182

target: target || (isExternal ? '_blank' : undefined),

171183

isExternal,

@@ -180,8 +192,8 @@ const linkRel = computed(() => {

180192

as,

181193

type,

182194

disabled,

183-

href: href,

184-

navigate: undefined,

195+

href,

196+

navigate,

185197

rel: linkRel,

186198

target: target || (isExternal ? '_blank' : undefined),

187199

isExternal

Original file line numberDiff line numberDiff line change

@@ -0,0 +1,9 @@

1+

import type { Plugin } from 'vue'

2+
3+

export default {

4+

install(app, options) {

5+

if (options?.router && typeof options.router === 'function') {

6+

app.provide('nuxtui:router', options.router)

7+

}

8+

}

9+

} satisfies Plugin

Read the original on github.com ↗