Laravel - How to redirect with hash (#)

后端 未结 3 880
谎友^
谎友^ 2021-02-03 10:43

I have link :

example.com/register#register

If validation fails laravel redirects to :

example.com/register

w

相关标签:
3条回答
  • 2021-02-03 10:59

    But if you want to get the proper URL where hash is the fragment part and not a parameter you should use:

    redirect(route('route_name', ['some_param_for_route']). '#hash')
    

    instead of:

    redirect()->route('route_name', [ 'some_param_for_route', '#hash' ])
    

    so to get:

    http://example.com/some_param_for_route#hash
    

    and not:

    http://example.com/some_param_for_route?#hash
    

    this way you can also chain it further like for instance:

    redirect(route('route_name', ['some_param']). '#hash')->with('status', 'Profile updated!');
    
    0 讨论(0)
  • 2021-02-03 11:01

    You could use helper:

    redirect()->route('route_name', [ 'some_param_for_route', '#hash' ])
    
    0 讨论(0)
  • 2021-02-03 11:02

    You could create the URL first, using the route name.

    $url = URL::route('route_name', ['#hash_tag']);
    
    Redirect::to($url);
    

    Or...

    return Redirect::to(URL::previous() . "#hash_tag");
    
    0 讨论(0)
提交回复
热议问题