Sandeep Kumar
Sandeep Kumar

Reputation: 1543

How to refresh content when using CrossroadJS and HasherJS with KnockoutJS

I was following Lazy Blogger for getting started with routing in knockoutJS using crossroads and hasher and it worked correctly.
Now I needed to refresh the content using ajax for Home and Settings page every time they are clicked. So I googled but could not find some useful resources. Only these two links

  1. Stack Overflow Here I could not understand where to place the ignoreState property and tried these. But could not make it work.

        define(["jquery", "knockout", "crossroads", "hasher"], function ($, ko, crossroads, hasher) {
    
        return new Router({
            routes:
            [
                { url: '', params: { page: 'product' } },
                { url: 'log', params: { page: 'log' } }
            ]
        });
    
        function Router(config) {
            var currentRoute = this.currentRoute = ko.observable({});
    
            ko.utils.arrayForEach(config.routes, function (route) {
                crossroads.addRoute(route.url, function (requestParams) {
                    currentRoute(ko.utils.extend(requestParams, route.params));
                });
            });
            activateCrossroads();
        }
    
        function activateCrossroads() {
            function parseHash(newHash, oldHash) {
                //crossroads.ignoreState = true; First try
                crossroads.parse(newHash);
            }
            crossroads.normalizeFn = crossroads.NORM_AS_OBJECT;
    
            hasher.initialized.add(parseHash);
            hasher.changed.add(parseHash);
            hasher.init();
    
            $('a').on('click', function (e) {
                crossroads.ignoreState = true; //Second try
            });
    
        }
    });
    
  2. Crossroads Official Page Here too I could not find where this property need to be set.

If you know then please point me to some url where I can get more details about this.

Upvotes: 1

Views: 423

Answers (0)

Related Questions