Skip to content
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

Add Global "Visit" Options Hook #1052

Merged
merged 3 commits into from
Jan 19, 2022
Merged

Conversation

claudiodekker
Copy link
Member

@claudiodekker claudiodekker commented Jan 17, 2022

This PR adds a global hook that's executed prior to any visit.
This allows for modifying headers etc. in a single place, instead of having to apply them globally.

Usage

While the URL itself is only available to conditionally apply actions (e.g. on a specific path/prefix) and cannot be modified, the options object itself can be adjusted. This options object essentially reflects your Visit options (everything available from an $inertia.get('/url', options) etc.).

createInertiaApp({
  // ...
  visitOptions(options, url) {
    options.headers = {
      'some-global-header': 'some-global-header-value'
    }
  
    return options
  }
})

@claudiodekker claudiodekker requested a review from reinink January 17, 2022 18:30
@claudiodekker claudiodekker merged commit 20b7782 into master Jan 19, 2022
@claudiodekker claudiodekker deleted the global-visit-options-hook branch January 19, 2022 15:42
@sebsobseb
Copy link

sebsobseb commented May 19, 2022

@claudiodekker Nice. Is this ready to be used? Because I couldn't find it in the documentation.

reinink added a commit that referenced this pull request Aug 9, 2022
reinink pushed a commit that referenced this pull request Sep 9, 2022
* add global visit options hook
reinink added a commit that referenced this pull request Sep 9, 2022
reinink pushed a commit that referenced this pull request Nov 3, 2022
* add global visit options hook
reinink added a commit that referenced this pull request Nov 3, 2022
reinink pushed a commit that referenced this pull request Nov 24, 2022
* add global visit options hook
reinink added a commit that referenced this pull request Nov 24, 2022
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