-
How do I send a piece of data in each and every request made to server? Let's say I want to send {foo: "bar"} in each and every request, how do I do it? It tried the before event, but I can't figure out how to modify outgoing data. I'm using Laravel/Vue 3 JS: PHP: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey! You can do this like this: import { router } from '@inertiajs/vue3'
router.on('before', (event) => {
event.detail.visit.data.foo = 'bar'
}) But I would discourage doing this, as for GET requests this is going to end up being I think it's better to send a header instead: import { router } from '@inertiajs/vue3'
router.on('before', (event) => {
event.detail.visit.headers.foo = 'bar'
}) Hope that helps. |
Beta Was this translation helpful? Give feedback.
Hey! You can do this like this:
But I would discourage doing this, as for GET requests this is going to end up being
/endpoint?foo=bar
, and forPOST/PUT/PATCH
it will be part of the body.I think it's better to send a header instead:
Hope that helps.