mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
feat(nuxt): await custom routes
function in router.options
(#27644)
This commit is contained in:
parent
97f3788009
commit
b026797d7b
6
packages/nuxt/src/pages/build.d.ts
vendored
Normal file
6
packages/nuxt/src/pages/build.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
declare module '#build/router.options' {
|
||||
import type { RouterOptions } from '@nuxt/schema'
|
||||
|
||||
const _default: RouterOptions
|
||||
export default _default
|
||||
}
|
@ -5,7 +5,6 @@ import { defineNuxtPlugin } from '#app/nuxt'
|
||||
import { prerenderRoutes } from '#app/composables/ssr'
|
||||
// @ts-expect-error virtual file
|
||||
import _routes from '#build/routes'
|
||||
// @ts-expect-error virtual file
|
||||
import routerOptions from '#build/router.options'
|
||||
|
||||
let routes: string[]
|
||||
|
@ -24,7 +24,6 @@ import { navigateTo } from '#app/composables/router'
|
||||
import { appManifest as isAppManifestEnabled } from '#build/nuxt.config.mjs'
|
||||
// @ts-expect-error virtual file
|
||||
import _routes from '#build/routes'
|
||||
// @ts-expect-error virtual file
|
||||
import routerOptions from '#build/router.options'
|
||||
// @ts-expect-error virtual file
|
||||
import { globalMiddleware, namedMiddleware } from '#build/middleware'
|
||||
@ -67,7 +66,7 @@ const plugin: Plugin<{ router: Router }> = defineNuxtPlugin({
|
||||
: createMemoryHistory(routerBase)
|
||||
)
|
||||
|
||||
const routes = routerOptions.routes?.(_routes) ?? _routes
|
||||
const routes = routerOptions.routes ? await routerOptions.routes(_routes) ?? _routes : _routes
|
||||
|
||||
let startPosition: Parameters<RouterScrollBehavior>[2] | null
|
||||
|
||||
|
@ -2,7 +2,7 @@ import type { RouterHistory, RouterOptions as _RouterOptions } from 'vue-router'
|
||||
|
||||
export type RouterOptions = Partial<Omit<_RouterOptions, 'history' | 'routes'>> & {
|
||||
history?: (baseURL?: string) => RouterHistory
|
||||
routes?: (_routes: _RouterOptions['routes']) => _RouterOptions['routes']
|
||||
routes?: (_routes: _RouterOptions['routes']) => _RouterOptions['routes'] | Promise<_RouterOptions['routes']>
|
||||
hashMode?: boolean
|
||||
scrollBehaviorType?: 'smooth' | 'auto'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user