- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在一个由 handlebarsJS 提供支持的 SPA 上使用 crossroadsJS 和 hasherJS。回想起来,我可能应该在 Ember 上构建整个东西,但已经晚了,重新开始并不明智。
我设置了哈希路由,可以根据点击的内容切换我的 Handlebars 模板。我可以毫无问题地在路线之间来回移动。但是,如果我刷新页面,我总是会回到我的#/home View 。我对 window.onhashchange 和 window.onbeforeunload 做了一些研究,但这些似乎都没有解决问题。
我有一个非常具体的方式来处理我的观点。我有一个像这样构造的全局 View 对象:
views.procedures = function (template) {
this.initialize = function () {
this.el = $('<div/>');
this.el.attr('id', 'procedures');
this.el.on('click', '.returned-list li a', this.toResults); // list of API objects by name
};
this.render = function () {
var parts = {
title: 'Procedures View',
};
this.el.html(template(parts));
return this;
};
this.toResults = function () {
cache.justClicked = $(this).attr('data-id');
crossroads.addRoute('procedures/{name}', function () {
api.endpoints.procedure(cache.justClicked); // constructed elsewhere
});
};
this.initialize();
};
我提到这一点是因为我不能简单地为 $(document).ready()
或 $(window).onhashchange< 中的任何类型的哈希更改添加 JQuery 监听器
我已经多次阅读 hasherJS 和 crossroadsJS 文档,但我想不出任何解决刷新问题的方法。在此先感谢您的帮助。
最佳答案
我需要你提供更多信息,但我假设你正在做
var DEFAULT_HASH = 'home';
if (! hasher.getHash()) {
hasher.setHash(DEFAULT_HASH);
}
这基本上是说您的默认路线始终是您的归宿路线,这就是为什么您在刷新当前路线时会看到它。尝试以下操作:
var DEFAULT_HASH = 'home', url = hasher.getBaseURL();
if (hasher.getURL() === url) {
hasher.setHash(DEFAULT_HASH);
}
这将检查您的基本 URL 是什么(您第一次访问该页面时加载的那个)并将 #/home
路由附加到基本 URL,允许您刷新当前查看路线。
希望这对您有所帮助。
关于javascript - 刷新 hasher JS/crossroads JS 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27713801/
我正在考虑使用 ZeroMQ 作为相当大的分布式系统的消息传递/传输层,主要针对监视和数据收集(许多生产者,一些消费者)。 据我所知,目前同一概念有两种不同的实现; ZeroMQ 和 Crossroa
有人可以帮我配置路由规则吗?我遇到了路由可选参数约束的问题。 应该为/{region}/{category}/{title}/:page: url pattern 调用名为“offerRegionCa
我正在一起测试 crossroads.js 和 hasher.js 以及第二次 setHash 调用上的以下代码错误,其中包含“Function.prototype.apply:参数不是对象”。这在
如何使用 crossroads.js 制作一个路由器系统,如果我转到以下 URL:localhost/user/{{username}},然后获取使用 firebase 在 URL 中输入的该用户的详
在得到一些关于问题的建议后,我正在使用基于 Linux 的软件来平衡两个服务器之间的流量。 基本上我们有我们的生产网站和备份系统(在远程站点)。生产不断地镜像到备份以保持同步。我们的域名指向 Linu
看起来 crossroads.js 比 router.js 更老。所有关于crossroads.js的文章似乎都是2011年的。我想知道是否有人有比较: 您选择其中一种而不是另一种的原因 运作方式的差
我在一个由 handlebarsJS 提供支持的 SPA 上使用 crossroadsJS 和 hasherJS。回想起来,我可能应该在 Ember 上构建整个东西,但已经晚了,重新开始并不明智。 我
我目前有这段代码: crossroads.addRoute('/login', function(){ $.ajax({ url: '/login', type
我使用 RequireJS 开发了一个应用程序,没有优化层 - 需要单独下载每个文件。这是外部标记: var require = { //some
我刚刚开始使用 crossroads.js和 hasher.js并且我已经成功解析了我的大部分路线。我不明白的是如何回到页面的根目录。我知道我说得不对,但这是我的问题: 我导航至 http://exa
我正在使用 knockout.js 和 crossroad.js。 (后者是由 yeoman 配置的。我不确定我是否需要它,但现在我不知道如何以其他方式设置项目。) 我有很多带有点击绑定(bind)的
ZeroC ICE 与 0MQ 相比如何?我知道 0MQ/Crossroads 和 DDS 非常相似,但似乎无法弄清楚 ICE 的用武之地。 我需要快速实现一个系统,将实时市场数据从 C++ 卸载到
我是一名优秀的程序员,十分优秀!