I'm new to SammyJS and I am running into an issue. I have my routes working, however when I access 1, and then i go to the other. It works. The problem is when I try to go back to the first route that I visited. I'm working with ASP.NET MVC and sammyjs.
Here is my code...
<script type="text/javascript" charset="utf-8">
debugger;
; (function ($) {
var app = $.sammy(function () {
debugger;
this.get('#/PartIndex', function () {
var routing = new Routing('@Url.Content("~/")', '#testing', 'CustomerDetail/CustomerEditDetailPartial');
routing.init();
});
this.get('#/ECheckbook', function () {
debugger;
var routing = new Routing('@Url.Content("~/")', '#testing', 'CustomerDetail/CustomerEditDetailPartial');
routing.init();
});
});
$(function () {
app.run()
});
})(jQuery);
<div class="page-container">
<a href="#/ECheckbook">Margin</a>
<br />
<a href="#/PartIndex">Main</a>
<div id="testing">
</div>
in my routing.js var Routing = function (appRoot, contentSelector, defaultRoute) {
function getUrlFromHash(hash) {
debugger;
var secondString = hash.split('/')[2];
var url = hash.replace('#/', '').replace(secondString + '/', '');
if (url === appRoot)
url = defaultRoute;
return url;
}
return {
init: function () {
Sammy(contentSelector, function () {
this.get(/\#\/(.*)/, function (context) {
var url = getUrlFromHash(context.path);
context.load(url).swap();
});
}).run('#/');
}
};
}