【问题标题】:How to include hashtag in Symfony routing如何在 Symfony 路由中包含主题标签
【发布时间】:2018-06-14 13:37:17
【问题描述】:

我需要像这样创建路由

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

所以它会在导航上打开特定的标签。

但我的路由没有按预期工作。

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

编辑:

我有三个标签 tab-A、tab-B、tab-C,我需要在点击 url 时显示与 tab-A 相关的产品列表:http://localhost:89/app_dev.php/list#tab-A。 (将选项卡 A 视为类别)。我需要 tab-A 作为 slug 参数,我们不喜欢像 http://localhost:89/app_dev.php/list/tab-A 这样的 url

【问题讨论】:

标签: symfony routing symfony-routing


【解决方案1】:

#gold-coin 未发送到服务器。请参阅此question 了解原因。

如果您想了解 slug 服务器端并希望拥有它的锚点,请使用类似这样的路由:/list/{slug},在您的 javascript 中,use location.href to change the anchor

如果你不想知道服务器端的锚点,use the _fragment parameter when displaying the url

【讨论】:

    【解决方案2】:

    在 v 3.2 中引入了对锚点的支持。对于使用fragment 变量的路由组件:

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

    会生成一个类似的url:/articles#comments

    欲了解更多信息view the announcement

    【讨论】:

      【解决方案3】:

      您对路由无能为力。

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

      与服务器相同:

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

      我认为anchor #something 只是用于客户端

      【讨论】:

        猜你喜欢
        • 2023-04-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-10-07
        • 2020-08-29
        • 1970-01-01
        • 2017-03-17
        • 1970-01-01
        相关资源
        最近更新 更多