'In CakePhp3 how to go back to respective page after clicking back button

I have detail page which can be access from other two pages. how to return to page that the user came from????

I have page like this:

page1 →index1→detail1→edit→confirm page

page2 →index2→detail2→edit→confirm page

currently I'm using below code

<div class="btn-clear"><a href="#" onclick="history.back(1);">Go Back</a></div>

but the problem is after going to confirm and click back button and user came to edit page.and if the user click back button on edit page where i have written above code error occurs.

error is:

Notice (8): Undefined variable:report[APP/Template/Reports/confirm.ctp, line 12]
Notice (8): Trying to get property of non-object [APP/Template/Reports/confirm.ctp, line 12]



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source