简体   繁体   中英

Laravel 5.2 how to redirect to a url with an anchor tag?

I want to redirect to a URL with an anchor tag so that it will automatically open the targetted tab.

ie redirect to www.test.com/amazing#so-amazing

In my experience, I can only redirect to the route that has my view option. I don't even know how I can attach the # anchor on the redirect option.

This is my return. Currently, I just set it to reload the page.

return response()->json([
            'status'      => 'success',
            'redirectUrl' => '',
        ]);

Since you only really need the route URL generated and the hash part of the URL is not dynamic you can just concat some strings together here:

'redirectUrl' => route('your.route', [...]) .'#yourhash';

Would give you your full URL string you were trying to build.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM