tbranyen/backbone-boilerplate — Issue #52: examples aren't clear enough
Author: secretgspot
Created: 2012-01-28 00:04:27+00:00
State: open

Example needs to be provided with more than just one page(view) and the rest redirects to the original view.

I've created a 2nd view and a template yet am having a nightmare of an issue with routing.

models
example.js
other.js

templates
example.html
other.html

var Router = Backbone.Router.extend({
routes: {
"": "index",
":hash": "index",
"other": "other"
},

index: function(hash) {
var route = this;
var tutorial = new Example.Views.Tutorial();

// Attach the tutorial to the DOM
tutorial.render(function(el) {
$("#main").html(el);

// Fix for hashes in pushState and hash fragment
if (hash && !route._alreadyTriggered) {
// Reset to home, pushState support automatically converts hashes
Backbone.history.navigate("", false);

// Trigger the default browser behavior
location.hash = hash;

// Set an internal flag to stop recursive looping
route._alreadyTriggered = true;
}
});
},
other: function() {
var other = new Example.Views.Other();

// Attach the tutorial to the DOM
other.render(function(el) {
$("#main").html(el);

});
}
});

Yet, what happens is. onclick page redirects to " /#other " then removes # leaving only " /other ". refreshing the page causes 404