Hello, I have found a solution to this.
Firstly you need to track the previous URL by setting up a prop that is tracked. This is done by adding an object to be passed through in App/Providers/AppServiceProvider.php. The following code will replacing the boot function (or if you are already passing objects/variables to the props just adding the 'urlPrevious' to your code) - also alternatively you can add thing into HandleInetiaRequests.php middleware & this would probably be a better location for this.
public function boot(): void
{
// inertia share data
Inertia::share([
'urlPrevious' => url()->previous(),
]);
}
Then in your Vue component, you need to add the following code to the script tag
// create a variable to hold the previous page url
let urlPrev = usePage().props.urlPrevious
// create a function to go back to the previous page via ajax request
const backPage = () => {
router.visit(urlPrev)
}
This will allow you to now call the "backPage" function in your inertia Link tag, you could use something like this:
<Link @click="backPage">
Back to previous page
</Link>
This solution works well & gives you a prop that can be useful in other places too.
However alternatively, you can use this and it will work. Then you don't need all the extra code and props set up, however there is times this could cause issues, such as if you have any partial reloads or anything that will cause the history to show the previous page as the same page you are on. I have run into this problem, so I worked out the solution above.
@click.prevent="window.history.back()"
I hope this helps you & anyone else that runs into this issue when they are searching for it. I have seen this question come up in the forums a few times so this should (fingers crossed) prevent more reposts of the same issues / question.