javascript - Backbone.js back button not loading proper view -


in backbone application, i'm trying figure out why when click button on page, url changes appropriately actual browser display not.

here's 1 flow:

  1. go application: elections/
  2. starting page: elections/#profile/manage/:id/
  3. page clicked to: elections/#profile/manage/:id/personalinfo/
  4. back button clicked. should end displaying elections/#profile/manage/:id/

however when button clicked, page display doesn't change, url.

i'm not sure what's causing nor how around this. i've read things options backbone.history.start() command, whenever add it, nothing displays.

not sure how go fixing problem. can point me in right direction? (i can expand code samples if need be, thought might easier read)

elections/app.js - called elections/index.html

require.config({      baseurl: 'js/lib',      paths: {         app: '../app',         tpl: '../tpl',         bootstrap: 'bootstrap/js/',      },      shim: {         'backbone': {             deps: ['underscore', 'jquery'],             exports: 'backbone'         },         'underscore': {             exports: '_'         },     } });  require([     'jquery',      'backbone',      'app/router', ], function ($, backbone, router) {     var router = new router();     backbone.history.start({pushstate:true}); }); 

elections/js/router.js - instantiated in app.js

define(function (require) {      "use strict";      var $           = require('jquery'),         backbone    = require('backbone'),         windowview   = require('app/views/window'),          breadcrumbs = {"home": ""},         $body = "",         $content = "",      return backbone.router.extend({          routes: {             ''                                                : 'home',              'profile/login(/)'                                : 'candidateprofilelogin',             'profile/manage(/)'                               : 'candidateprofilelogin',             'profile/manage/:id(/)'                           : 'candidateprofilehome',             'profile/manage/:id/:section(/)'                  : 'candidateprofilesection',         },          initialize: function () {             require([], function () {                 $body = $('body');                 windowview = new windowview ({el: $body}).render();                 $content = $("#content", windowview .el);             });         },          candidateprofilehome: function (id) {             require(["app/views/candidate", "app/models/candidate"], function (candidateview, models) {                 var candidate = new models.candidate({id: id});                 console.log('router: candidateprofilehome');                 candidate.fetch({                     success: function (data, response) {                         var view = new candidateview({model: data, el: $content});                         view.render();                     },                     error: function (data, response) {                         var view = new candidateview({model: data, el: $content});                         view.render();                     }                 });                  breadcrumbs['profile home'] = backbone.history.fragment;                 windowview.addbreadcrumbs(breadcrumbs);                 windowview.selectmenuitem('candidate-menu');             });         },          candidateprofilesection: function (id, section) {             require(["app/views/candidate", "app/models/candidate"], function (candidateview, models) {                 var sectionnames = {                     'questionnaire': 'questionnaire',                     'endorsements' : 'endorsements',                     'photo'        : 'photo',                 };                 var sectionname = sectionnames[section];                  var candidate = new models.candidate({id: id});                 candidate.fetch({                     success: function (data, response) {                         var view = new candidateview({model: data, el: $content});                         view.render(section);                     },                     error: function (data, response) {                         //output data console. let template take care of error pages                         console.log(data);                         var view = new candidateview({model: data, el: $content});                         view.render(section);                     }                 });                  breadcrumbs['profile home'] = "profile/manage/" + id + "/";                 breadcrumbs[sectionname] = backbone.history.fragment;                 windowview.addbreadcrumbs(breadcrumbs);                 windowview.selectmenuitem('candidate-menu');             });         },          candidateprofilequestionnaire: function (id, page) {             require(["app/views/candidate", "app/models/candidate"], function (candidateview, models) {                 var pagenames = {                     'personalinfo': 'personal information',                     'essay'       : 'biography & essay',                     'survey'      : 'survey questions',                     'endorsements': 'endorsements',                     'photo'       : 'photo'                 };                 var pagename = "questionnaire: " + pagenames[page];                  var candidate = new models.candidate({password: id});                 candidate.fetch({                     success: function (data, response) {                         console.log('success');                         var view = new candidateview({model: data, el: $content});                         view.render(page);                     },                     error: function (data, response) {                         //output data console. let template take care of error pages                         console.log('error');                         console.log(data);                         var view = new candidateview({model: data, el: $content});                         view.render(page);                     }                 });                  breadcrumbs['profile home'] = "profile/manage/" + id + "/";                 breadcrumbs[pagename] = backbone.history.fragment;                 windowview.addbreadcrumbs(breadcrumbs);                 windowview.selectmenuitem('candidate-menu');             });         },     }); }); 

you shouldn't need configure backbone's router handle browsers history state or events, it's built in. issue lies somewhere else...in case view, rendering template.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -