【问题标题】:backbone routing not working on refresh主干路由在刷新时不起作用
【发布时间】:2012-11-14 10:11:33
【问题描述】:

我已经把这个演示放在一起

http://demo.stg.brightonconsulting.net.au/templates/tests/backboneJQMProducts/

目前只有顶部链接“products json pull”有效。如果您单击您将被带到一个新页面(http://demo.stg.brightonconsulting.net.au/templates/tests/backboneJQMProducts/index.html#products/productList)

到此页面的路由工作正常,但是当您刷新页面时,它不显示该页面,它只显示一个空白页面? (它可以刷新 - 执行 cntr+f5 你会看到)

以前有没有人遇到过这种情况/有人知道修复方法是什么吗?

我已尝试编辑此代码

define(['jquery','underscore', 'backbone','router'],
function($, _, Backbone,Router) {

var init=function(){
    //create backbone router
    //location.hash = '';
    var router=new Router();
    Backbone.history.start();
};

return{
    initialize:init
}
});

基于推荐。

我正在使用 require.js 将应用程序放在一起,这是从 main.js 调用的,它由 require 实例化

require.config({

paths: {
    jquery:     'vendor/jqm/jquery_1.7_min',
    jqm:     'vendor/jqm/jquery.mobile-1.1.0', 
    underscore: 'vendor/underscore/underscore_amd',
    backbone:   'vendor/backbone/backbone_amd',
    text:       'vendor/require/text',
    plugin:    'plugin',
    templates:  '../templates',
    views:    '../views',
    models:       '../models'
}

});


define(['app','jqm-config'], function(app) {
$(document).ready(function() {
  console.log("DOM IS READY");// Handler for .ready() called.
});    
app.initialize();
});

谢谢丹

【问题讨论】:

  • 我无法在我的 chrome 上重现该错误。
  • 发生在我的 ff 上,更重要的是在我的手机上。手段可以将人们发送到一个无用的直接链接...这可能与我使用 require.js 的方式有关吗?定义方法?
  • 您对此有什么解决方案吗?我也面临同样的问题。以下答案都没有帮助我。请恢复
  • @sSaroj 你解决了这个问题吗?
  • @vini 不。我没有。

标签: backbone.js underscore.js


【解决方案1】:

我刚刚在使用 RequireJS 设置 BackboneJS 后遇到了类似的情况。

我从我的路由器代码中调用Backbone.history.start();为了解决这个问题,我将此调用移到了在我的主 require() 函数中实例化我的视图之后。

希望对某人有所帮助。

【讨论】:

    【解决方案2】:

    根据您想要实现的行为,您可以做两件事:

    在初始化路由之前重置哈希。

    location.hash = ''
    var router=new Router();
    Backbone.history.start();
    

    您可以在初始化路由后导航到该哈希标记。

    var router=new Router();
    Backbone.history.start();
    router.navigate(location.hash, true)
    

    【讨论】:

    • 您好,谢谢您。如果我同时尝试这两种方法,它不会显示空白页面,但会重新引导我到我的应用程序的开头...我真的希望它留在我的页面上我在..
    • @sebastian stackoverflow.com/questions/38320519/… 你能帮我解决这个问题吗
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-26
    • 1970-01-01
    • 1970-01-01
    • 2012-08-17
    • 1970-01-01
    • 2019-02-24
    相关资源
    最近更新 更多