将 url 更改为哈希片段变体

发布于 2024-12-26 12:28:38 字数 513 浏览 1 评论 0原文

它看起来不像简单的哈希pushState,因为它确实改变了整个url。

没有页面刷新+它通过将其全部切断并将其作为哈希片段再次推送到 url 来完全更改 url。请查看下面的示例。

访问例如网址: http://www.couverts.nl/restaurant/13233 /jo-van-den-bosch/den-bosch

立即更改为: http://www.couverts.nl/# /restaurant/13233/jo-van-den-bosch/den-bosch

有人知道这里使用的技术吗?也许有人可以举一个简单的例子来说明如何实现它。

It doesnt look like simple hashing pushState since its really changing the whole url.

There is no page-refresh + it is totaly changing the url by cutting it all off and pushing it to the url again as a hash fragment. Please checkout the example below.

visit for example the url:
http://www.couverts.nl/restaurant/13233/jo-van-den-bosch/den-bosch

which instantly gets changed to:
http://www.couverts.nl/#/restaurant/13233/jo-van-den-bosch/den-bosch

Anyone know the techinque used here? And maybe someone can give a simple example of how to implement it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆梦 2025-01-02 12:28:38

我也在密切关注这个问题:Apache 重写指令怎么样?一个快速而肮脏的方法是:

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} -f
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule ^(.*)$ index.php/#/$1

然后 index.php 读取路径做一些工作并简单地将标头发送到客户端

header('Location: http://www.example.com/#/bla/bla')

这背后的整个想法当然是 AJAX 和前端控制器模式。

PS:我刚刚重写了 Quentin Zervaas 所著《Practical Web 2.0 Applications with PHP》一书中与 Zend_Controller 类相关的第 2 章“将所有请求定向到 index.php”中的一些 Apache 指令...

I'm also looking close to this issue: what about Apache rewrite directives? A quick and dirty one would be:

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} -f
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule ^(.*)$ index.php/#/$1

and then index.php reads the path do some work and simply sends a header to client

header('Location: http://www.example.com/#/bla/bla')

The whole idea behind this is of course AJAX and the Front Controller pattern.

PS: I've just rewritten some Apache directives from "Directing All Requests to index.php" of Chapter 2 related with the Zend_Controller class from the book "Practical Web 2.0 Applications with PHP" by Quentin Zervaas...

请帮我爱他 2025-01-02 12:28:38

在不刷新页面的情况下更改 URL 使用了非常新的历史记录 API,主要是 history.replaceState

本杰明·巴勒普顿(Benjamin Balupton)写了非常好的history.js

我也邀请您检查整个规范:http://dev.w3.org/html5/spec/history.html

仅更改 location.hash 是这里的简单部分。

Changing the URL with no page refresh uses the very new history API, mostly history.replaceState

Benjamin Balupton has written the very good history.js

And I invite your to check the whole specifications too: http://dev.w3.org/html5/spec/history.html

Changing only the location.hash is the easy part here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文