Search code examples
symfonyurlsymfony-routing

How to use anchors in Symfony routing?


I have defined a route as followed in my routing.yml file :

route_name:
    path: "/dashboard#messages/{id}"

However when I ask Symfony to generate that route, I get :

/dashboard%23messages/12345

How can I skip the encoding part of the route generation? Or how can I escape the # char in the path definition?

PS : Working with a (big) legacy system, I cannot change the urls.


Solution

  • Available from Symfony 3.2.

    Support for anchors has been announced for the routing component using the fragment variable :

    $this->get('router')->generate('user_settings', ['_fragment' => 'password']);
    

    Will generate an url : /user/settings#password

    For more information view the announcement.