【问题标题】:URL changing with window.location.hash but not pageURL 随 window.location.hash 而不是 page
【发布时间】:2017-10-30 11:48:12
【问题描述】:

我正在尝试在淘汰赛中实现单页应用程序,并且我正在单击链接以返回页面。 URL 正在更改,但仍保留在同一页面上。只有在刷新时它才会进入所需的页面。

我正在使用window.location.hash = "#/home" 在 URL 中设置链接。 知道可以做什么,以便页面根据 URL 实际更改。

【问题讨论】:

  • 你目前正在做什么来检测哈希变化?
  • Home 这调用了一个改变url的函数

标签: javascript jquery knockout.js single-page-application window.location


【解决方案1】:

使用事件onhashchangelike,

window.onhashchange = function(){
   // change your page content here
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-05
    • 1970-01-01
    • 2016-08-15
    • 2018-07-04
    • 1970-01-01
    • 2018-12-14
    • 2021-07-17
    相关资源
    最近更新 更多