【发布时间】:2013-02-11 02:04:19
【问题描述】:
在 SPA 中,使用 Sammy.js 等导航框架,我如何在页面中使用名为锚点的页面进行页面内导航?
例如假设我有一个类似localhost/myapp/#/somerecord/1 的路由,应用程序在其中加载 id = 1 的 somerecord。
然而 somerecord 真的很复杂很长。我希望能够使用命名锚点跳转到某个部分。
假设文章元素被定义为<article id=section-d> ... </article>,我只是链接到<a href=#section-d>Section D</a>,它在技术上是有效的,但URL 看起来像localhost/myapp/#section-d,这会破坏导航堆栈。点击返回按钮让我回到localhost/myapp/#/somerecord/1 并且没有跳回顶部。
首选的操作是跳回顶部或上一页。关于如何实现这一点的任何想法?
【问题讨论】:
-
这是 stackoverflow.com/q/10113103/829970 的副本,但只有一个错误的答案(即没有 sammy.js 的纯 Javascript 的答案)。
标签: html single-page-application sammy.js