Skip to content

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.

@pascalbaljet
Copy link
Member Author

I've revisited this idea and it might be cool to follow Laravel's bootstrap/app.php approach:

createInertiaApp({
  resolve: (name) => resolvePageComponent(`./pages/${name}.vue`, import.meta.glob('./pages/**/*.vue')),
  setup({ el, App, props, plugin }) {
    createApp({ render: () => h(App, props) })
      .use(plugin)
      .use(ZiggyVue)
      .mount(el)
  },
})
  .withVisits((href, options) => ({
    queryStringArrayFormat: 'indices',
    headers: {
      'X-Custom-Header': 'CustomValue',
    },
  }))
  .withPrefetch({
    cache: '45s',
  })
  .withProgress({
    delay: 500,
    color: '#ff0000',
  })

We could also provide a config() helper to retrieve and set config values:

import { config } from '@inertiajs/vue3'

const allConfig = config()
const color = config('progress.color')

// Set single values with dot notation
config('progress.delay', 300)

// Set multiple values at once
config({
  progress: { delay: 250, color: '#29d' },
})

@pascalbaljet
Copy link
Member Author

I'm closing this one in favor of other plans.

@pascalbaljet
Copy link
Member Author

New PR: #2655

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.

2 participants