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,
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.
Please or to participate in this conversation.