JSFiddle - React, Tailwind, and code Playground

by beewayne

JavaScript

define('router',
    ['jquery', 'sammy', 'client'],
    function ($, Sammy, client) {

        var defaultRoute,
            currentHash;

        var sammy = new Sammy.Application(function() {
            if (Sammy.Title) {
                this.use(Sammy.Title);
                this.setTitle('Order Management > ');
            }

            this.get('', function() {
                this.app.runRoute('get', '/');
            });
        });
        
        sammy.before(/.*/, function () {
            // Can cancel the route if this returns false
            var context = this;
            
            if (context.params.clientId) {
                client.setId(context.params.clientId);
            }
            
            currentHash = context.app.getLocation();

            return true;
        });

        var validateRoute = function(route, param_length) {
            param_length = param_length || 0;
            var sammyRoute = sammy.lookupRoute('get', route);
            if (sammyRoute !== false && sammyRoute.param_names.length >= param_length) {
                return true;
            }
            return false;
        };


        var registerRoute = function(options) {
            if (!options.call) {
                throw Error('call must be specified.');
            }

            if (options.isDefault) {
                defaultRoute = options.route;
            }
            
            sammy.get(options.route, function(context) { //context is 'this'
                //store.save(config.stateKeys.lastView, context.path);
                options.call(context.params);
                 // Activate the viewmodel
                //presenter.transitionTo(
                //    $(options.view),
                //    context.path,
                //    options.group
                //);
                if (this.title) {
                    this.title(options.title);
                }
            });

        };

        var register = function(options)...