The title pretty much summarizes exactly my problem. I have my login controller, and I'd like to redirect to previous page after login. E.g., If I am viewing the Contact Us page, then I log in, I'd like to be redirected back to the Contact Us page. Just wondering the best way to achieve this.
You could check referrer.
$controller->redirect_to($controller->req->headers->referrer);
It is maybe not as beautiful solution as the one above, but I use a parameter to pass the url of 'previous' page (back_url). If the parameter is empty, I can setup a default page to land on.
my $self = shift;
my $back_url = $self->param('back_url');
$back_url = '/publications' if $back_url eq $self->req->url->to_abs or $back_url eq '';
# code here
$self->redirect_to($back_url);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With