0

I need to create routing like

http://localhost:89/app_dev.php/list#gold-coin

So it will open specific tab on navigation.

But my routing not working as expected.

shop_product:
    path: /list#{slug}
    methods: [GET] 

Edit:

I have three tabs tab-A, tab-B, tab-C and I need to display list of products related to tab-A on clicking url: http://localhost:89/app_dev.php/list#tab-A. (consider tab-A as category). I need tab-A as a slug parameter and we are not preferring url like http://localhost:89/app_dev.php/list/tab-A

stefun
  • 893
  • 1
  • 20
  • 49
  • 1
    http://symfony.com/blog/new-in-symfony-3-2-routing-improvements – Cerad Jun 14 '18 at 13:43
  • It is not clear what you are asking for. You can generate url's with fragments easy enough. But are you trying to actually extract the slug and pass it onto your list controller? That won't work. – Cerad Jun 14 '18 at 13:56
  • @Cerad: edited question – stefun Jun 14 '18 at 15:00
  • https://stackoverflow.com/questions/940905/can-i-read-the-hash-portion-of-the-url-on-my-server-side-application-php-ruby Just not going to happen. – Cerad Jun 14 '18 at 15:03

3 Answers3

2

The #gold-coin is not send to the server. See this question to know why.

If you want to know the slug server side and you want to have its anchor, use a route like this one : /list/{slug} and, in your javascript, use location.href to change the anchor.

If you do not want to know the anchor on the server side, use the _fragment parameter when displaying the url.

LP154
  • 1,449
  • 11
  • 16
1

Support for anchors has been introduced in the v 3.2. For the routing component using the fragment variable :

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

Will generate an url like: /articles#comments

For more information view the announcement.

Matteo
  • 32,801
  • 10
  • 89
  • 100
0

There is not much you can do with routing about this.

http://localhost:89/app_dev.php/list#gold-coin

Is the same as for the server:

http://localhost:89/app_dev.php/list

The anchor #something is just used client side I reckon