inertia-laravel
inertia-laravel copied to clipboard
How to create back or previous button on inertia-laravel
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 ?
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.
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
Thanks for your help here @herpaderpaldent and @sagalbot!
@adiramardiani You can also just use window.history.back() to go back in history in JavaScript.