page not found when i login and go back (Laravel 7 - JS)

Viewed 72

I made a duplication of the mercadolibre application for study purposes only.

Add this "favorites" button ({image circle 1}) and the problem is as follows:

When they click on the button and you are not logged in, it redirects you to the login form. Then you log in and it is redirected to the previous page, then you can successfully add to favorites. But when I use the "return to list" button ({image circle 2}), which is a javascript:history.back () then it sends me a "page not found" error. Any idea how to fix it?

this is what i used in my LoginComtroller.php to redirect to the previous page after login

public function showLoginForm(Request $request)
{
    if(!session()->has('url.intended')) 
    { 
    session(['url.intended' => url()->previous()]); 
    } 
    return view('auth.login');
}

Ps: sorry for my bad english

enter image description here

1 Answers

When your session has 'url.intended', then you for your button ({image circle 2}), you can use blade to render the route...or pass the url of the route to the front end and redirect with js instead of javascript:history.back().

Related