Nav.js is a wrapper around History.js that is included when a VS11 SPA project is created.
We create a NavHistory object as follows:
var nav = new NavHistory({
params: { view: 'View1' },
onNavigate: function (navEntry) {
alert("Display" + navEntry.params.view);
}
}
});
nav.initialize({ linkToUrl: true });//Nothing works if set to false
Next we handle a menu click event, which causes the view to change - hence we want to add that to the browser back button history. We do that by calling nav.navigate:
Hi, Christoff, I believe this is because of the line:
params: { view: 'View1' },
which is being initialised with the default view. This triggers a callback on the onNavigate immediately. I can't tell you exactly because we wrote some wrapper code around this, and now it's difficult to tell what the original was up to. Noel
Noel Abraham...
Member
6 Points
18 Posts
Nav.js onNavigate being called twice
Apr 22, 2012 07:41 PM|LINK
Hi,
Nav.js is a wrapper around History.js that is included when a VS11 SPA project is created.
We create a NavHistory object as follows:
var nav = new NavHistory({ params: { view: 'View1' }, onNavigate: function (navEntry) { alert("Display" + navEntry.params.view); } } }); nav.initialize({ linkToUrl: true });//Nothing works if set to falseNext we handle a menu click event, which causes the view to change - hence we want to add that to the browser back button history. We do that by calling nav.navigate:
this.onMenuClick = function () { alert('Menu clicked'); nav.navigate({ view: "View2" }); };The problem: After the initial page re-load, when the menu item is clicked, we get one alert of "Menu clicked", but 2 alerts of "Display View2".
Can someone please advise on a solution?
Thanks!
christoffler...
Member
2 Points
1 Post
Re: Nav.js onNavigate being called twice
Jan 11, 2013 09:22 AM|LINK
Hi Noel, did you manage to solve the problem. I'm having the same issue here.
Regards
Christoff
Noel Abraham...
Member
6 Points
18 Posts
Re: Nav.js onNavigate being called twice
Jan 15, 2013 11:42 AM|LINK
Hi, Christoff, I believe this is because of the line:
params: { view: 'View1' },which is being initialised with the default view. This triggers a callback on the onNavigate immediately. I can't tell you exactly because we wrote some wrapper code around this, and now it's difficult to tell what the original was up to. Noel