Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ignaMani's avatar

Do a router.post request without changing the URL?

DELETED

0 likes
9 replies
Nakov's avatar

When posting the request params go in the body of the request, not in the url. So you can just merge them like this:

const benchmarkCompare = () => {
    router.post('/analytics/account/'+currentAccount.id+'/summary', {
    ...this.$route.query,
        activeBenchmarkAccounts: activeBenchmarkAccounts,
        selectedIds: benchmarkModalSelectedAccounts.value,
        currentAccount: currentAccount,
    }, {
        only: ['activeBenchmarkAccounts'],
        onSuccess: () => {
          benchmarkModalOpen.value = false
        }
    })
  }
Nakov's avatar

@ignaMani I don't know the context in which you are running this function my friend, I am not sure where do you have the router defined as well..

maybe this refers to something else in your context, you can try debugging console.log(this.$route) if it returns anything at all.

ignaMani's avatar

@Nakov I'm just using this once a button is pressed I just need to pass the activeBenchmark selectedIds currentAccount, then once selectedIds are passed into a controller activeBenchmarkAccounts gets returned filled with values. I used it this way because I can use the ``ònly``` so I only modify the prop that I need. This is executing well but I dont need to get the URL changed.

Nakov's avatar

@ignaMani okay, so the only is the one that removes them from the body possibly. Try this then:

router.post('/analytics/account/'+currentAccount.id+'/summary?' + new URLSearchParams(this.$route.query).toString(), { ...
ignaMani's avatar

@Nakov It's like I do not have this.$route defined, this is just a method that goes into vue 3 file which sends the data into a Laravel Controller to have some accounts returned and change them once accounts are selected from a checkbox and a button is pressed. Maybe it would be easier if I used axios instead of router?

Nakov's avatar

@ignaMani what about if you replace that with router.params or just $route without this. at the beginning?

1 like
Nakov's avatar

@ignaMani you are defining it as $benchmarkaccounts = [] and then trying to use it benchmarkAccounts so A should be upper case.

$benchmarkAccounts = [];
ignaMani's avatar

@Nakov Yeah saw that and fixed it too. Unfortunately with that fixed router.post still modifying the URL.

Please or to participate in this conversation.