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

kea_rajab's avatar

Ziggy redirect back

For laravel using just blade you can do

url()->previous()

to redirect back to the page you came from... but am using vue backed up with inertia... using ziggy routes.. I went through the documentation of ziggy js and found some methods like route().current()... which works fine in vue... but how Can i accomplish the same using ziggy or other means to return to previous page using vue and ziggy routes... Thanks in advance

0 likes
11 replies
Sinnbeck's avatar

I dont think ziggy has that ability. But if you just want to go back (same as the back button in the browser)

window.history.back();
kea_rajab's avatar

i tried this but couldnt...

            <a :href="window.history.back()" class="font-semibold flex items-center hover:text-gray-500 transition duration:150 ease-in">

compile error

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

It isnt a url... So it should be on click instead

kea_rajab's avatar

it broke the liink... i tried even putting it in a function but it redirects to some gibberish link with the function name on it...

Sinnbeck's avatar

That sounds weird. Does the same happen if you call it from the browser console?

Sinnbeck's avatar

I cant say why that is then..

An alternative is to use your original :href with document.referrer. That should be the previous url

kea_rajab's avatar

well, thanks for your effort, i tried this one... but now it goes forth and back... instantly... as soon as the components are created then it changes back to where it came from... dont know if there would be 'prevent' or something to wait untill its clicked

kea_rajab's avatar

finally it worked, i put it in a function called clicked, and used a data called back

<a @click="clicked" :href="back" class="font-semibold flex items-center hover:text-gray-500 transition duration:150 ease-in">

and the function

data(){
            return {
                back: '',
            }
        },

clicked(){
                this.back = window.history.back()
            },

thanks @sinnbeck

tykus's avatar

You don't need to know the URL; the previous page is in the browser's History which Vue Router can access easily:

router.go(-1) // go back one page
kea_rajab's avatar

am using ziggy not router directly

1 like

Please or to participate in this conversation.