在 URL 中间使用 /#/

Pla*_*ato 5 url fragment-identifier

我最近遇到了一个 Web 应用程序,其 URL 具有以下形式:

https://URL.com/page/uuid/#/anotheruuid/area?action=whatever
Run Code Online (Sandbox Code Playgroud)

我对#在 URL 中的使用感到困惑。通常,井号是为位于 URL 末尾的片段标识符保留的。这里有什么用,它的目的是什么?

Bau*_*umi 9

这通常用于 SPA(单页应用程序)。目的是能够在不同页面之间移动而无需重新加载整个页面。这是客户端框架/库能够正确路由应用程序的信息。

例如,最常见的框架之一 - Angular - 支持两种定位策略:

  1. URL 看起来像的HashLocationStrategyhttp://localhost/#/product
  2. PathLocationStrategy 其中 URL 看起来像http://localhost/product

来源