Skip to content

Ability to configure defaults in createInertiaApp() #2419

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pascalbaljet
Copy link
Member

Definitely WIP, but I'm already opening this to gather feedback/input.

This PR introduces a new defaults key to the CreateInertiaAppProps interface, allowing you to define application-wide defaults.

For example, you can use it to change the default queryStringArrayFormat from brackets to indices, or to attach default headers to every request:

createInertiaApp({
  title: (title) => `${title} - ${appName}`,

  // ...resolve, setup, progress, etc...

  defaults: {
    visitOptions: (href, options) => {
      return {
        queryStringArrayFormat: 'indices',
        headers: {
          'X-Foo': 'bar',
        },
      }
    },
  },
})

I've chosen to nest visitOptions under defaults so we don't bloat CreateInertiaAppProps if we end up adding more of these callbacks later on.

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.

1 participant