-
-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathvueRouterModule.ts
40 lines (33 loc) · 1.21 KB
/
vueRouterModule.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// NOTE: this code needs to be generated because otherwise it doesn't go through transforms and `vue-router/auto-routes`
import type { ResolvedOptions } from '../options'
// cannot be resolved.
export function generateVueRouterProxy(
_routesModule: string,
_options: ResolvedOptions,
{ addPiniaColada }: { addPiniaColada: boolean }
) {
return `
import { createRouter as _createRouter } from 'vue-router'
export * from 'vue-router'
export { definePage } from 'unplugin-vue-router/runtime'
export {
DataLoaderPlugin,
NavigationResult,
} from 'unplugin-vue-router/data-loaders'
export * from 'unplugin-vue-router/data-loaders/basic'
${addPiniaColada ? "export * from 'unplugin-vue-router/data-loaders/pinia-colada'" : ''}
export function createRouter(options) {
const { extendRoutes, routes } = options
// use Object.assign for better browser support
if (extendRoutes) {
console.warn('"extendRoutes()" is deprecated, please modify the routes directly. See')
}
const router = _createRouter(Object.assign(
options,
{ routes: typeof extendRoutes === 'function' ? (extendRoutes(routes) || routes) : routes },
))
return router
}
`.trimStart()
}
// FIXME: remove `extendRoutes()` in the next major version