From 8094f62f5871988611d82e857867064b2d959189 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 14 Feb 2024 16:39:23 +0100 Subject: [PATCH] refactor!: remove `setupLoaderGuard` BREAKING CHANGE: The navigation guard is replaced in favor of a Vue plugin: Replace ```ts import { setupLoaderGuard } from 'vue-router/auto' setupLoaderGuard({ router, app }) ``` with ```ts import { DataLoaderPlugin } from 'vue-router/auto' app.use(DataLoaderPlugin, { router }) ``` --- client.d.ts | 3 +-- docs/rfcs/data-loaders/index.md | 12 ++++-------- examples/nuxt/pages/users/[id].vue | 2 +- src/codegen/vueRouterModule.ts | 3 +-- src/data-fetching_new/meta-extensions.spec.ts | 2 ++ src/index.ts | 13 ++----------- src/runtime.ts | 2 -- 7 files changed, 11 insertions(+), 26 deletions(-) diff --git a/client.d.ts b/client.d.ts index b7454c087..ddd598054 100644 --- a/client.d.ts +++ b/client.d.ts @@ -105,8 +105,7 @@ declare module 'vue-router/auto' { export { definePage, DataLoaderPlugin, - _setupLoaderGuard as setupLoaderGuard, - _defineBasicLoader as defineBasicLoader, + defineBasicLoader, // FIXME: remove these in next major _HasDataLoaderMeta as HasDataLoaderMeta, _setupDataFetchingGuard as setupDataFetchingGuard, diff --git a/docs/rfcs/data-loaders/index.md b/docs/rfcs/data-loaders/index.md index 53b933a7f..f4e99e53f 100644 --- a/docs/rfcs/data-loaders/index.md +++ b/docs/rfcs/data-loaders/index.md @@ -129,7 +129,7 @@ By default, **data loaders block the navigation**, meaning they _just work_ with The simplest of data loaders can be defined in just one line and types will be automatically inferred: ```ts twoslash -import { _defineBasicLoader as defineLoader } from 'unplugin-vue-router/runtime' +import { defineBasicLoader as defineLoader } from 'unplugin-vue-router/runtime' interface Book { title: string isbn: string @@ -227,19 +227,15 @@ const app = createApp(App) app.use(DataLoaderPlugin, { router }) ``` -### `setupLoaderGuard()` +### The Plugin -`setupLoaderGuard()` setups a navigation guard that handles all the loaders. It has a few options - -#### `app` - -The Vue app instance created with `createApp()` +`DataLoaderPlugin` adds the navigation guard that handles the data loaders. It requires access to the router instance to attach the navigation guard as wel as some other options #### `router` The Vue Router instance. -#### `selectNavigationResult` +#### `selectNavigationResult` (optional) Called wih an array of `NavigationResult` returned by loaders. It allows to decide the _fate_ of the navigation. diff --git a/examples/nuxt/pages/users/[id].vue b/examples/nuxt/pages/users/[id].vue index ee04847ae..474a61ee0 100644 --- a/examples/nuxt/pages/users/[id].vue +++ b/examples/nuxt/pages/users/[id].vue @@ -1,5 +1,5 @@