Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

chabwino's avatar

Login redirect to previous page with hash

Hi! When I'm navigating to a page with a hash like my-page.com/users#/show/10 but I am redirected to the login page first, then after login I get redirected to my-page.com/users# but everything behind the hash is lost. How can I fix that?

I'm working with an upgraded laravel 8 application with the old standard Auth functions (is it called breeze now?)

0 likes
1 reply
chabwino's avatar

As nobody answered to my question, let me show you what I ended up doing:

In the login form I added two hidden fields

<input type="hidden" id="frmUrl" name="url" value="">
<input type="hidden" id="frmUrlHash" name="urlHash" value=""> 

Then I filled these fields with js:

document.getElementById('frmUrl').value = '{{url()->previous()}}';
document.getElementById('frmUrlHash').value = window.location.hash;

In LoginController i added the following override:

    public function redirectTo()
    {
        $params = request()->request->all();

        return $url === config('app.url')
            ? '/home'
            : $params['url'] . $params['urlHash'];
    }

Works fine so far.

Please or to participate in this conversation.