Skip to content

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

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.

@HichemTab-tech
Copy link
Contributor Author

This PR was closed due to mistakenly deleted fork, here's the re-attempt #2485.

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