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

madprabh's avatar

Back button in Jetstream application

Hey everyone,

So I am building an application using Laravel jetstream and I am wondering how do I implement a back button on a form, for example

The user click on Creating a project but later changes mind, if there is a "Nevermind" button (href link), how can I have it go to the previous url?

I am using Jetstream+inertia+vue,

0 likes
5 replies
MohamedTammam's avatar
Level 51

Just use a normal Link component to the page you want the use to be redirected to

import { Link } from '@inertiajs/inertia-vue3'

<Link href="back/path">Back</Link>

There's no way (as far as I know) to get the previous URL using Inertia because it doesn't store that info on the front-end.

If you want to go extra, you can add the previous URL in your Inertia shared data

In your HandleInertiaRequests middleware

public function share(Request $request)
    {
        return array_merge(parent::share($request), [
            'previous_url' => url()->previous(),
			// ...
        ]);
    }

In your front-end

import { Link } from '@inertiajs/inertia-vue3'

<Link href="$page.props.previous_url">Back</Link>

But approach will not always work because as intended, because sometime the previous URL is the same as the current one.

madprabh's avatar

@MohamedTammam Thanks a lot bro! This works like a charm and you taught me something new. I could actually pass more information in the shared data function...

1 like

Please or to participate in this conversation.