Backbone / Parse app:链接在首次加载时不起作用

时间:2014-06-21 20:47:43

标签: javascript backbone.js parse-platform single-page-application

我正在使用Parse JS库创建单页Web应用程序,这是Backbone的扩展。

我的路由器设置如下:

var AppRouter = Parse.Router.extend({
    routes: {
      "": "signup",
      "signup": "signup",
      "login": "login",
      "logout": "logout",
      "dashboard": "dashboard",
      "history": "history",
      "account": "account"
    },

    initialize: function(options) {
    },

    login: function() {
      this.navigateTo(new LoginView(), false);
    },

    logout: function() {
      Parse.User.logOut();
      Parse.history.navigate("signup", true);
    },

    signup: function() {
      this.navigateTo(new SignupView(), false);
    },

    dashboard: function() {
      this.navigateTo(new DashboardView(), true);
    },

    history: function () {
      this.navigateTo(new SentMailView(), true);
    },

    account: function () {
      this.navigateTo(new AccountView(), true);
    },

    navigateTo: function(view, needsSignedIn) {
      if (needsSignedIn && !Parse.User.current()) {
        Parse.history.navigate("signup", true);
      } else if (!needsSignedIn && Parse.User.current()) {
        Parse.history.navigate("dashboard", true);
      } else {
        this.loadView(view);
      }
    },

    loadView: function(view) {
      this.view && (this.view.close ? this.view.close() : delete this);
      this.view = view;
    }
  });

main.js结束时,我创建了新的路由器,查看并将pushState设置为true:

new AppRouter;
new AppView;
Parse.history.start({pushState: true});

我遇到的问题是偶尔(通常在我第一次加载应用程序的页面时),没有任何链接可以工作,他们所做的就是刷新页面。例如,点击指向' / history'的链接没有加载历史页面,它只是重新加载当前页面。同样,单击指向触发js调用的bootstrap下拉菜单的链接也将重新加载当前页面。刷新浏览器(通过刷新按钮)通常会修复此问题,然后所有链接都能正常工作。

知道为什么会这样吗?

1 个答案:

答案 0 :(得分:0)

修正了它。该问题是由未正确删除的基础视图引起的。这个视图有一个函数被绑定到"点击" event - 单击任何元素。相同的功能被绑定到仪表板视图中所有链接上的点击事件,这是我不想要的。

相关问题