inertia-laravel icon indicating copy to clipboard operation
inertia-laravel copied to clipboard

How to create back or previous button on inertia-laravel

Open adiramardiani opened this issue 3 years ago • 2 comments
trafficstars

Hi

Sorry If this is just a question, close this issued if you're all have the best approach and answer, I hope this is can be added on documentation / routing section

For normal blade I just use

<a class="btn btn-info" href="{{ URL::previous() }}"> Back </a>

On the other hand vue-router can write something like

<a @click="$router.back()"> Back </>

How to do this on inertia, especially on laravel vue/react ?

adiramardiani avatar Oct 17 '22 16:10 adiramardiani

Better to ask such things on discord. But if it is not a static route to navigate back, you could use a prop from the controller.

herpaderpaldent avatar Oct 17 '22 16:10 herpaderpaldent

Agree with @herpaderpaldent, but you can solve this by passing URL::previous() as a prop. You can do that either in your controller where you render your inertia component, or you could add it to the shared data for every view.

// ShowDashboardController.php

return Inertia::render('Dashboard/ShowDashboard', [
    'url' => [ 'previous' => URL::previous()]
]);
// in your react or vue component
usePage().props.url.previous

sagalbot avatar Nov 01 '22 21:11 sagalbot

Thanks for your help here @herpaderpaldent and @sagalbot!

@adiramardiani You can also just use window.history.back() to go back in history in JavaScript.

reinink avatar Jan 17 '23 01:01 reinink