本文介绍了使用Sammy.js时如何移动到页面的锚点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Sammy.js,它可以处理所有客户端URL导航.我想导航到/page#fragment,但是该页面实际上不会转到#fragment.如何使其自动或通过编写代码进入片段来做到这一点?

I'm using Sammy.js, and it handles all the client-side URL navigation. I want to navigate to /page#fragment, but the page wont actually go to #fragment. How can I make it do that, either automatically, or by writing code to go to the fragment?

推荐答案

Sammy不会自动触发路由,因此在您的处理程序中,您需要添加:

Sammy doesnt automatically trigger the route, so in your handler you need to add:

hash = window.location.hash
if(hash != '') {
    window.location.hash = hash;
}

这篇关于使用Sammy.js时如何移动到页面的锚点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 17:07
查看更多