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

NoLAstNamE's avatar

Inertia.js route visit/get redirect

I want to redirect to another page when I call a function inside the Vue script. Has anyone here done this before?

This is what I tried but it's not working as I'm expecting it to work.

<script setup>
const handleClick = () => {
   router.visit(route("my-route-here"), {
       method: "get",
   });
};
</scritp>

I know that there's Inerita's Link but I can't use it because the element that is being clicked doesn't always need to redirect to the route.

EDIT:

The redirect is working now. But the problem is, that the query parameters aren't added in the URL.

<script setup>
const handleClick = () => {
   router.visit(route("my-route-here"), {
       method: "get",
       data: {
           foo: 'bar',
       },
   });
};
</scritp>

What I'm expected above is, that the foo is appended to the URL of route("my-route-here").

0 likes
3 replies
NoLAstNamE's avatar
NoLAstNamE
OP
Best Answer
Level 8

I managed to solve it. I used router.get. Inertia Manual visits confuse me sometimes, there's always room for improvement in their docs.

Here's the code:

const handleClick = () => {
   router.get(route("my-route-here"), {
       { foo: 'bar' },
       { preserveScroll: true }
   });
};
2 likes

Please or to participate in this conversation.