Nav.js onNavigate being called twice RRS feed

  • Question

  • User1277704360 posted


    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:

            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?


    Sunday, April 22, 2012 3:41 PM

All replies

  • User599528884 posted

    Hi Noel, did you manage to solve the problem. I'm having the same issue here.



    Friday, January 11, 2013 5:22 AM
  • User1277704360 posted

    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

    Tuesday, January 15, 2013 7:42 AM