Results 1 to 9 of 9

Thread: 6.5.0: redirectTo force is ignored

    Success! Looks like we've fixed this one. According to our records the fix was applied for EXTJS-25308 in 6.5.1.
  1. #1
    Sencha Premium Member
    Join Date
    Jul 2009
    Posts
    8

    Default 6.5.0: redirectTo force is ignored

    We use redirectTo-method (http://docs.sencha.com/extjs/6.5.0/c...hod-redirectTo) with force option
    That worked fine in 6.2 but in 6.5.0 the Router skips the execution.

    In the redirectTo-method the force-option is handled: (if using with 6.2 signature. The new 6.5 signature of the method (Object instead of Boolean) does not set the force-var)
    if (force) {
    //hash won't change, trigger handling anyway
    Router.onStateChange(hash);
    }

    But the Router skips the execution (in doRun) because of route.recognize(token) returning true.

  2. #2
    Sencha Premium Member richardvd's Avatar
    Join Date
    Jun 2011
    Location
    NL
    Posts
    255

    Default

    I created two overrides to fix this:

    Code:
    Ext.define('Override.route.Router', {
        override : 'Ext.route.Router',
    
        clearLastTokens: function () {
            var routes = this.routes,
                name;
    
            for (name in routes) {
                route = routes[name];
                route.lastToken = null;
            }
        }
    });
    Code:
    Ext.define('Override.route.Mixin', {
        override: 'Ext.route.Mixin',
    
        requires: [
            'Ext.route.Router',
            'Ext.util.History'
        ],
    
        redirectTo: function (hash, opt) {
            var currentHash = Ext.util.History.getToken(),
                Router      = Ext.route.Router,
                delimiter   = Router.getMultipleToken(),
                force,
                i, tokens, length,
                name, obj, route, token, match;
    
            if (hash === -1) {
                return Ext.util.History.back();
            } else if (hash === 1) {
                return Ext.util.History.forward();
            } else if (hash.isModel) {
                hash = hash.toUrl();
            } else if (Ext.isObject(hash)) {
                i      = 0;
                tokens = currentHash ? currentHash.split(delimiter) : [];
                length = tokens.length;
    
                //Passing an object attempts to replace a token in the hash.
                for (name in hash) {
                    obj = hash[name];
    
                    if (!Ext.isObject(obj)) {
                        obj = {
                            token: obj
                        };
                    }
    
                    if (length) {
                        route = Router.getByName(name);
    
                        if (route) {
                            i = 0;
                            match = false;
    
                            for (; i < length; i++) {
                                token = tokens[i];
    
                                if (route.matcherRegex.test(token)) {
                                    match = true;
    
                                    if (obj.token) {
                                        //a token was found in the hash, replace it
                                        if (obj.fn && obj.fn.call(this, token, tokens, obj) === false) {
                                            //if the fn returned false, skip update
                                            continue;
                                        }
    
                                        tokens[i] = obj.token;
                                    } else {
                                        //remove token
                                        tokens.splice(i, 1);
    
                                        i--;
                                        length--;
    
                                        //reset lastToken
                                        route.lastToken = null;
                                    }
                                }
                            }
    
                            if (obj && obj.token && !match) {
                                //a token was not found in the hash, push to the end
                                tokens.push(obj.token);
                            }
                        }
                    } else if (obj && obj.token) {
                        //there is no current hash, push to the end
                        tokens.push(obj.token);
                    }
                }
    
                hash = tokens.join(delimiter);
            }
    
            //for backwards compatibility
            if (opt === true) {
                force = opt;
                opt = null;
            }
    
            if (opt && opt.force) {
                force = opt.force;
            }
    
            if (currentHash === hash) {
                if (force) {
                    //hash won't change, trigger handling anyway
                    Router.clearLastTokens();
                    Router.onStateChange(hash);
                    return true;
                }
    
                //hash isn't going to change, return false
                return false;
            }
    
            if (opt && opt.replace) {
                Ext.util.History.replace(hash);
            } else {
                Ext.util.History.add(hash);
            }
    
            return true;
        }
    },
    function() {
        // auto override this mixin in already existing classes
        var me = this,
            reservedPropertiesRe = [
                '^\\$.*', '^_.*', 'afterClassMixedIn', 'alias', 'alternateClassName', 
                '^apply.*', 'cachedConfig', 'config', 'defaultConfig', '^destroy.*', 
                'extend', '^get.*', 'inheritableStatics', 'mixinConfig', 'mixinId', 
                'mixins', 'override', 'onClassMixedIn', 'platformConfig', 'privates', 
                'requires', 'self', '^set.*', 'singleton', 'statics', 'superclass', 
                '^update.*', 'uses', 'xtype'            
            ],
            re = new RegExp(reservedPropertiesRe.join("|"));
        
        Ext.Object.each(Ext.ClassManager.classes, function(name, targetClass) {
            if (targetClass.prototype && targetClass.prototype.mixins) {
                Ext.Object.each(targetClass.prototype.mixins, function(id, targetMixinClass) {
                    var mixinClassName = targetMixinClass.$className,
                        overrideClassName = me.prototype.$className;
    
                    if (mixinClassName===overrideClassName) {
                        Ext.Object.each(me.prototype, function(propertyName, newClass) {
                            if ( !re.test(propertyName)
                                && ( newClass!==targetClass.prototype[propertyName] )) {
                                targetClass.prototype[propertyName] = newClass;
                            }
                        });
                    }
                });
            }
        }, this);
    });
    

  3. #3
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,256

    Default

    Thanks for the report! I have opened a bug in our bug tracker.

  4. #4

    Default

    Hi,

    I've also the same issue (with ExtJs v6.5.0.775).
    Could you let me know if this issue is already fixed on the latest nightlies build or not yet ?


    Best regards.

  5. #5

  6. #6

    Default

    Hi Denis,

    I downloaded the latest nightly build (ExtJs 6.5.1.205 and Cmd 6.5.1.229).
    And this issue is now fixed.

  7. #7
    Sencha User
    Join Date
    Oct 2013
    Posts
    55

    Default

    In 6.5.3 this is still not works if current token is '':

    me.redirectTo('', {force: true});

    I need to write everywhere:

    if (Ext.util.History.getToken() == '') Ext.route.Router.clearLastTokens('');

    Please, fix it.

  8. #8
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,448

    Default

    Quote Originally Posted by zdm View Post
    In 6.5.3 this is still not works if current token is '':

    me.redirectTo('', {force: true});

    I need to write everywhere:

    if (Ext.util.History.getToken() == '') Ext.route.Router.clearLastTokens('');

    Please, fix it.
    This is a different issue, the force option is working but there is another bug that you are reporting.

    The issue you are seeing is the line in the redirectTo that says:

    Code:
    tokens = currentHash ? currentHash.split(delimiter) : [],
    If you are using an empty hash, then currentHash will be falsy and therefore use an empty array in that ternary. The simple fix is to check if it's defined:

    Code:
    tokens = currentHash == null ? [] : currentHash.split(delimiter),
    I personally never use an empty string, I normally have a default token like home or dashboard (name depends on the app). Here's a fiddle I created to show the fix:

    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  9. #9
    Sencha User
    Join Date
    Oct 2013
    Posts
    55

    Default

    Thank you for reply.
    I hope, that sencha will include this patch into the core.

Similar Threads

  1. [OPEN] Ext.app.BaseController redirectTo force bug
    By jonw in forum Ext 5: Bugs
    Replies: 6
    Last Post: 21 Jan 2016, 12:29 PM
  2. bug of redirectTo
    By elijah.zhao in forum Ext 5: Q&A
    Replies: 5
    Last Post: 20 May 2015, 11:50 AM
  3. this.redirectTo() called twice at the end?
    By Don Pipo in forum Sencha Touch 2.x: Q&A
    Replies: 3
    Last Post: 14 Mar 2013, 5:17 AM
  4. Routing and redirectTo()
    By discobean in forum Sencha Touch 2.x: Q&A
    Replies: 2
    Last Post: 10 Jul 2012, 4:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •