Skip to content

pass props as second argument to resolve() in createInertiaApp #2330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

HichemTab-tech
Copy link
Contributor

@HichemTab-tech HichemTab-tech commented Apr 29, 2025

Description

This PR adds props as a second argument to the resolve function in createInertiaApp.

The goal is to provide more context when resolving pages which is useful for setups where you want custom loading behavior based on the props.

Use case

In a Laravel app using modules (like nwidart/laravel-modules), pages can live inside each module. With this change, you can dynamically load the correct page component based on a prop like module:

resolve: (name, props) => {
      let path = `./pages/${name}.tsx`;
      if (props.module) {
            path = `../../Modules/${props.module}/resources/js/pages/${name}.tsx`;
      }
      return resolvePageComponent(path, {
          ...import.meta.glob('./pages/**/*.tsx'),
          ...import.meta.glob('./../../Modules/*/resources/js/pages/**/*.tsx')
      }))
  },

This is just an example of my implementation, there are a lot of use cases where this can be useful.

This way, you're not limited to a single flat Pages directory , you can load pages from multiple modules depending on the current route's props.

Impact

No impact on existing setups

@@ -6,7 +6,7 @@ import {
Component,
Page,
PageEvent,
PageHandler,
PageHandler, PageProps,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
PageHandler, PageProps,
PageHandler,
PageProps,

@Andy9822
Copy link

+1 it'd be nice to have access to the props in the resolve function

@pascalbaljet
Copy link
Member

I understand the use case and I think I'd be a good addition. I'm going to discuss this internally and then I'll get back to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants