diff --git a/packages/core/src/router.ts b/packages/core/src/router.ts index a60f5558d..e0d350034 100644 --- a/packages/core/src/router.ts +++ b/packages/core/src/router.ts @@ -449,7 +449,7 @@ export class Router { preserveState?: PreserveStateOption } = {}, ): Promise { - return Promise.resolve(this.resolveComponent(page.component)).then((component) => { + return Promise.resolve(this.resolveComponent(page.component, page)).then((component) => { if (visitId === this.visitId) { page.scrollRegions = page.scrollRegions || [] page.rememberedState = page.rememberedState || {} @@ -481,7 +481,7 @@ export class Router { if (event.state !== null) { const page = event.state const visitId = this.createVisitId() - Promise.resolve(this.resolveComponent(page.component)).then((component) => { + Promise.resolve(this.resolveComponent(page.component, page)).then((component) => { if (visitId === this.visitId) { this.page = page this.swapComponent({ component, page, preserveState: false }).then(() => { diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 2fc1d6025..66daa8d76 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -43,7 +43,7 @@ export interface Page { rememberedState: Record } -export type PageResolver = (name: string) => Component +export type PageResolver = (name: string, page: Page) => Component export type PageHandler = ({ component, diff --git a/packages/react/src/createInertiaApp.ts b/packages/react/src/createInertiaApp.ts index 2a83c4111..fd22ee309 100644 --- a/packages/react/src/createInertiaApp.ts +++ b/packages/react/src/createInertiaApp.ts @@ -78,11 +78,11 @@ export default async function createInertiaApp Promise.resolve(resolve(name)).then((module) => module.default || module) + const resolveComponent = (name, page) => Promise.resolve(resolve(name, page)).then((module) => module.default || module) let head = [] - const reactApp = await resolveComponent(initialPage.component).then((initialComponent) => { + const reactApp = await resolveComponent(initialPage.component, initialPage).then((initialComponent) => { return setup({ // @ts-expect-error el, diff --git a/packages/svelte/src/createInertiaApp.js b/packages/svelte/src/createInertiaApp.js index facb5e625..abd106cda 100644 --- a/packages/svelte/src/createInertiaApp.js +++ b/packages/svelte/src/createInertiaApp.js @@ -7,9 +7,9 @@ export default async function createInertiaApp({ id = 'app', resolve, setup, pro const isServer = typeof window === 'undefined' const el = isServer ? null : document.getElementById(id) const initialPage = page || JSON.parse(el.dataset.page) - const resolveComponent = (name) => Promise.resolve(resolve(name)) + const resolveComponent = (name, page) => Promise.resolve(resolve(name, page)) - await resolveComponent(initialPage.component).then((initialComponent) => { + await resolveComponent(initialPage.component, initialPage).then((initialComponent) => { store.set({ component: initialComponent, page: initialPage, diff --git a/packages/vue2/src/app.ts b/packages/vue2/src/app.ts index 2ba3cd706..cf75566a7 100755 --- a/packages/vue2/src/app.ts +++ b/packages/vue2/src/app.ts @@ -8,7 +8,7 @@ import useForm from './useForm' export interface InertiaProps { initialPage: Page initialComponent?: object - resolveComponent?: (name: string) => Component + resolveComponent?: (name: string, page: Page) => Component titleCallback?: (title: string) => string onHeadUpdate?: (elements: string[]) => void } diff --git a/packages/vue2/src/createInertiaApp.ts b/packages/vue2/src/createInertiaApp.ts index 8c38ef85b..103d760be 100644 --- a/packages/vue2/src/createInertiaApp.ts +++ b/packages/vue2/src/createInertiaApp.ts @@ -4,7 +4,7 @@ import App, { InertiaApp, InertiaProps, plugin } from './app' interface CreateInertiaAppProps { id?: string - resolve: (name: string) => Component | Promise | { default: Component } + resolve: (name: string, page: Page) => Component | Promise | { default: Component } setup: (props: { el: Element App: InertiaApp @@ -40,11 +40,11 @@ export default async function createInertiaApp({ const el = isServer ? null : document.getElementById(id) const initialPage = page || JSON.parse(el.dataset.page) // @ts-expect-error - const resolveComponent = (name) => Promise.resolve(resolve(name)).then((module) => module.default || module) + const resolveComponent = (name, page) => Promise.resolve(resolve(name, page)).then((module) => module.default || module) let head = [] - const vueApp = await resolveComponent(initialPage.component).then((initialComponent) => { + const vueApp = await resolveComponent(initialPage.component, initialPage).then((initialComponent) => { return setup({ el, App, diff --git a/packages/vue3/src/app.ts b/packages/vue3/src/app.ts index dde3254c5..e509c554a 100755 --- a/packages/vue3/src/app.ts +++ b/packages/vue3/src/app.ts @@ -18,7 +18,7 @@ import useForm from './useForm' export interface InertiaAppProps { initialPage: Page initialComponent?: object - resolveComponent?: (name: string) => DefineComponent | Promise + resolveComponent?: (name: string, page: Page) => DefineComponent | Promise titleCallback?: (title: string) => string onHeadUpdate?: (elements: string[]) => void } diff --git a/packages/vue3/src/createInertiaApp.ts b/packages/vue3/src/createInertiaApp.ts index 8d69214eb..afe660cfe 100644 --- a/packages/vue3/src/createInertiaApp.ts +++ b/packages/vue3/src/createInertiaApp.ts @@ -4,7 +4,7 @@ import App, { InertiaApp, InertiaAppProps, plugin } from './app' interface CreateInertiaAppProps { id?: string - resolve: (name: string) => DefineComponent | Promise | { default: DefineComponent } + resolve: (name: string, page: Page) => DefineComponent | Promise | { default: DefineComponent } setup: (props: { el: Element; App: InertiaApp; props: InertiaAppProps; plugin: Plugin }) => void | VueApp title?: (title: string) => string progress?: @@ -31,11 +31,11 @@ export default async function createInertiaApp({ const isServer = typeof window === 'undefined' const el = isServer ? null : document.getElementById(id) const initialPage = page || JSON.parse(el.dataset.page) - const resolveComponent = (name) => Promise.resolve(resolve(name)).then((module) => module.default || module) + const resolveComponent = (name, page) => Promise.resolve(resolve(name, page)).then((module) => module.default || module) let head = [] - const vueApp = await resolveComponent(initialPage.component).then((initialComponent) => { + const vueApp = await resolveComponent(initialPage.component, initialPage).then((initialComponent) => { return setup({ el, App,