Skip to content

Commit

Permalink
feat: explicitely allow for the data fetching guard
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Aug 25, 2022
1 parent 996ee86 commit 5f672b2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
8 changes: 7 additions & 1 deletion playground/src/main.ts
@@ -1,6 +1,10 @@
import { createApp } from 'vue'
import App from './App.vue'
import { createWebHistory, createRouter } from 'vue-router/auto'
import {
createWebHistory,
createRouter,
setupDataFetchingGuard,
} from 'vue-router/auto'

const router = createRouter({
history: createWebHistory(),
Expand All @@ -10,6 +14,8 @@ const router = createRouter({
},
})

setupDataFetchingGuard(router)

const app = createApp(App)

app.use(router)
Expand Down
15 changes: 2 additions & 13 deletions src/codegen/vueRouterModule.ts
Expand Up @@ -5,16 +5,11 @@ import type { ResolvedOptions } from '../options'
// cannot be resolved.
export function generateVueRouterProxy(
routesModule: string,
{ dataFetching }: ResolvedOptions
options: ResolvedOptions
) {
return `
import { routes } from '${routesModule}'
import { createRouter as _createRouter } from 'vue-router'
${
dataFetching
? `import { _setupDataFetchingGuard } from 'unplugin-vue-router/runtime'`
: ``
}
export * from 'vue-router'
export {
Expand All @@ -32,13 +27,7 @@ export function createRouter(options) {
options,
{ routes: typeof extendRoutes === 'function' ? extendRoutes(routes) : routes },
))
${
dataFetching
? `
_setupDataFetchingGuard(router)
`
: ``
}
return router
}
`
Expand Down
4 changes: 3 additions & 1 deletion src/data-fetching/README.md
Expand Up @@ -2,8 +2,10 @@

⚠️ Warning: This is an experimental feature and API could change anytime

- [RFC discussion](https://github.com/vuejs/rfcs/discussions/460): Note that not everything is implemented yet.

## Installation

Install the unplugin-vue-router library as described in its [main Readme](../../README.md)
Install the unplugin-vue-router library as described in its [main `README.md`](../../README.MD)

## Usage

0 comments on commit 5f672b2

Please sign in to comment.