Skip to content

Commit bab9d0b

Browse files
committed
docs: nuxt
1 parent 36fdd81 commit bab9d0b

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

docs/data-loaders/nuxt.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Nuxt
2+
3+
To use Data Loaders in Nuxt, create a new plugin file in the `plugins` directory of your Nuxt project and setup the Data Loaders plugin like usual:
4+
5+
```ts
6+
// plugins/data-loaders.ts
7+
import { DataLoaderPlugin } from 'unplugin-vue-router/data-loaders'
8+
9+
export default defineNuxtPlugin({
10+
name: 'data-loaders',
11+
dependsOn: ['nuxt:router'],
12+
setup(nuxtApp) {
13+
const appConfig = useAppConfig()
14+
15+
nuxtApp.vueApp.use(DataLoaderPlugin, {
16+
router: nuxtApp.vueApp.config.globalProperties.$router,
17+
isSSR: import.meta.server,
18+
// other options...
19+
})
20+
},
21+
})
22+
```
23+
24+
The two required options are:
25+
26+
- `router`: the Vue Router instance
27+
- `isSSR`: a boolean indicating if the app is running on the server side
28+
29+
## No module?
30+
31+
> "Why do I need to write the plugin myself instead of using a Module?"
32+
33+
The Data Loader plugin has options that are not serializable (e.g. `selectNavigationResult()` and `errors`). In order to support those within a module, we would have to pass them through the `app.config.ts`, splitting up the configuration and making it harder to maintain. A short plugin is easier to understand and closer to the _vanilla_ version.

0 commit comments

Comments
 (0)