At sometimes your application or website developed with Laravel Framework, there is a need to, via a “link”, allow user to return to the URL- Page or route, previously called.

This is commonly necessary when showing a HTTP 404 error message screen - Page Not Found, or 403 - Forbidden (unauthorized).

However, it is not always interesting to set up this link through the History browser navigation, which can be achieved by the Back method in JavaScript.

The example of code in JavaScript to return to the previous navigation URL would be:

history.back()

As I said above, it is not always interesting to use this function because our user may have reached this point of the system through redirections, and it is necessary to guarantee the previous route correctly.

Another problem is related to the SEO of your application that can be harmed if the search engine does not correctly identify the links on the pages that tracking.

Therefore the best strategy is to set up this URL address using the [components that the laravel](/components-of-the-fuchitecture components/) provides to developer.

You can set up the URL using two different strategies: in the controller or directly on the Blade view template. If you set up it in the controller you should pass to the view a variable with this information.

Redirection for previous URL in the Controller

To direct the user directly from the controller to the previous route, you must return from an action of this controller that will send to the browser the correct redirect information.

This is a strategy that does not set up the URL on the screen for the user, but it meets project needs if you are in a flow where your application needs to make the decision to redirect the user to the previous route.

Use for this the helper back():

function actionController()
{
   ...

   // Returns with Redirect to the last route
   return back();
}

Or even using helper redirect with the back method:

function actionController()
{
   ...

   // Returns with Redirect to the last route
   return redirect()->back();
}

Using this strategy you can still add user input variables to the route that will be called, or even error information:

function actionController()
{
   ...

   // Returns with redirect to the last route, with user inputs and error message
   return redirect()
      ->back()
      ->withInput()
      ->withErrors(['My error message']);
}

But if you need to show the URL to the user, so that it click on it and a search engine can index this information, do this directly on the view.

Set up previous URL on View with Blade

If you want to set up a link on the screen for the user to click and return to the page previously navigated by it, use the helper url that correctly assembles the URLs of your application, calling the method previous:

<a  href="{{ url()->previous() }}">
    <i class="fa fa-arrow-circle-o-left"></i>
    <span>Back</span>
</a>

This way you can click the link and the search engine can properly assemble the link tree from your site or application if necessary.