gpt4 book ai didi

angularjs - 我可以从 AngularJS 收回对 URL 哈希片段的控制吗?

转载 作者:行者123 更新时间:2023-12-03 20:42:07 25 4
gpt4 key购买 nike

我正在使用 AngularJS,并想处理给定的 #hash-fragment在地址栏中。然而,——这是关键——我不会使用散列片段来编码路径。但似乎 AngularJS 坚持以这种方式解释它。

例如,当 html5Mode被禁用:

  • 给定的 URL:http://my.domain.com#my-hash
  • 变成了http://my.domain.com/#/my-hash , 和
  • $location.hash()将是空的。

  • html5Mode已启用:
  • 给定的 URL:http://my.domain.com#my-hash
  • 变成了http://my.domain.com/my-hash , 和
  • $location.hash()仍将是空的。

  • AngularJS 一定在想:“哦,你有 html5,让我为你删除那个哈希”。多么体贴……

    $location.hash() 获得任何东西的唯一途径是当 URL 具有双哈希值时:
  • 对于给定的 URL:http://my.domain.com##my-hash
  • $location.hash()最终等于 "my-hash" , 和
  • 如果还有$locationProvider.html5Mode(true)哈希值之一从 URL 中删除。

  • 但我真的需要一个简单的单个哈希字符来保持未处理状态。这可能吗?

    最佳答案

    #在angular api docs页面上似乎工作得很好。所以通过一点窥探和测试,我发现

    app.config(function($locationProvider) {
    $locationProvider.html5Mode(true).hashPrefix('!');
    });

    有所作为。

    关于angularjs - 我可以从 AngularJS 收回对 URL 哈希片段的控制吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20268213/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com