【问题标题】:Rails Hash parameter in the URL Rails RoutesURL Rails Routes 中的 Rails Hash 参数
【发布时间】:2016-08-08 03:32:34
【问题描述】:

我正在尝试模拟与 gmail 相同的行为,其中 URL 会根据您单击的链接而变化,例如 https://mail.google.com/mail/u/0/#inbox

此链接显示如何add a Hash parameter in the URL Rails Routes

然后可以使用jquery to modify the URL hash to add the hash parameter when the view is loaded

根据我的测试,以下路由 /route#sent 在服务器中被视为 /route

我缺少的部分难题如何route to the corresponding route as the hash parameter is not sent to the server

【问题讨论】:

  • 服务器无法将 url 哈希作为 request 参数的一部分。一种肮脏的方法将涉及 jQuery。在页面加载时,您可以检查 url 是否有哈希。如果是/route#sent,你可以从JS向/route?query=sent之类的东西发出请求。当这个页面加载时,url 不会有 hash,你的 JS 会从 url 到 /route#sent 组合 hash。

标签: jquery ruby-on-rails ruby


【解决方案1】:

散列后的部分主要用于浏览器。在加载的页面上,如果 hash 变化 1000 次,浏览器不会向服务器请求任何东西!

使用 JS 框架(如 Angular/Vue)或 jQuery 来检测哈希变化并相应地加载内容!

【讨论】:

    猜你喜欢
    • 2011-10-26
    • 2015-03-05
    • 1970-01-01
    • 1970-01-01
    • 2015-12-07
    • 1970-01-01
    • 1970-01-01
    • 2017-04-29
    • 1970-01-01
    相关资源
    最近更新 更多