src/navigation.js
function cleanNavigate(doc, replace = false) {
    let navigated = false;
    let docs = navigationDocument.documents;
    let last = getLastDocumentFromStack();

    if (!replace && (!last || last !== loaderDoc && last !== errorDoc)) {
        pushDocument(doc);
    } else if (last && last === loaderDoc || last === errorDoc) { // replaces any error or loader document from the current document stack
        console.log('replacing current error/loader...');
        replaceDocument(doc, last);
        loaderDoc = null;
        errorDoc = null;
    }
    // determine the current document on the navigation stack
    last = replace && getLastDocumentFromStack();
    // if replace is passed as a param and there is some document on the top of stack
    if (last) {
        console.log('replacing current document...');
        replaceDocument(doc, last);
    }

    // dismisses any modal open modal
    _.delay(dismissModal, 2000);

    return docs[docs.length - 1];
}
function cleanNavigate(doc, replace = false) {
    let navigated = false;
    let docs = navigationDocument.documents;
    let last = getLastDocumentFromStack();

    if (!replace && (!last || last !== loaderDoc && last !== errorDoc)) {
        pushDocument(doc);
    } else if (last && last === loaderDoc || last === errorDoc) { // replaces any error or loader document from the current document stack
        console.log('replacing current error/loader...');
        replaceDocument(doc, last);
        loaderDoc = null;
        errorDoc = null;
    }
    // determine the current document on the navigation stack
    last = replace && getLastDocumentFromStack();
    // if replace is passed as a param and there is some document on the top of stack
    if (last) {
        console.log('replacing current document...');
        replaceDocument(doc, last);
    }

    // dismisses any modal open modal
    _.delay(dismissModal, 2000);

    return docs[docs.length - 1];
}
function cleanNavigate ( doc , replace = false ) { let navigated = false ; let docs = navigationDocument . documents ; let last = getLastDocumentFromStack ( ) ; if ( ! replace && ( ! last || last !== loaderDoc && last !== errorDoc ) ) { pushDocument ( doc ) ; } else if ( last && last === loaderDoc || last === errorDoc ) { // replaces any error or loader document from the current document stack console . log ( 'replacing current error/loader...' ) ; replaceDocument ( doc , last ) ; loaderDoc = null ; errorDoc = null ; } // determine the current document on the navigation stack last = replace && getLastDocumentFromStack ( ) ; // if replace is passed as a param and there is some document on the top of stack if ( last ) { console . log ( 'replacing current document...' ) ; replaceDocument ( doc , last ) ; } // dismisses any modal open modal _ . delay ( dismissModal , 2000 ) ; return docs [ docs . length - 1 ] ; }
Performs a navigation by checking the existing document stack to see if any error or loader page needs to be replaced from the current stack

@private

@param   {Document} doc              The document that needs to be pushed on to the navigation stack
@param   {Boolean} [replace=false]   Whether to replace the last document from the navigation stack
@return  {Document}                  The current document on the stack
Performs a navigation by checking the existing document stack to see if any error or loader page needs to be replaced from the current stack