src/navigation.js
function navigate(page, options, replace) {
    let p = Page.get(page);

    if (_.isBoolean(options)) {
        replace = options;
    } else {
        options = options || {};
    }

    if (_.isBoolean(options.replace)) {
        replace = options.replace;
    }

    console.log('navigating... page:', page, ':: options:', options);

    // return a promise that resolves if there was a navigation that was performed
    return new Promise((resolve, reject) => {
        if (!p) {
            console.error(page, 'page does not exist!');
            let tpl = defaults.templates.status['404'];
            if (tpl) {
                let doc = showError({
                    template: tpl,
                    title: '404',
                    message: 'The requested page cannot be found!'
                });
                resolve(doc);
            } else {
                reject();
            }
            return;
        }

        p(options).then((doc) => {
            // support suppressing of navigation since there is no dom available (page resolved with empty document)
            if (doc) {
                // if page is a modal, show as modal window
                if (p.type === 'modal') {
                    // defer to avoid clashes with any ongoing process (tvmlkit weird behavior -_-)
                    _.defer(presentModal, doc);
                } else { // navigate
                    // defer to avoid clashes with any ongoing process (tvmlkit weird behavior -_-)
                    _.defer(cleanNavigate, doc, replace);
                }
            }
            // resolve promise
            resolve(doc);
        }, (error) => {
            // something went wrong during the page execution
            // warn and set the status to 500
            if (error instanceof Error) {
                console.error(`There was an error in the page code. ${error}`);
                error.status = '500';
            }
            // try showing a status level error page if it exists
            let statusLevelErrorTpls = defaults.templates.status;
            let tpl = statusLevelErrorTpls[error.status];
            if (tpl) {
                showError(_.defaults({
                    template: tpl
                }, error.response));
                resolve(error);
            } else {
                console.warn('No error handler present in the page or navigation default configurations.', error);
                reject(error);
            }
        });
    });
}
function navigate(page, options, replace) {
    let p = Page.get(page);

    if (_.isBoolean(options)) {
        replace = options;
    } else {
        options = options || {};
    }

    if (_.isBoolean(options.replace)) {
        replace = options.replace;
    }

    console.log('navigating... page:', page, ':: options:', options);

    // return a promise that resolves if there was a navigation that was performed
    return new Promise((resolve, reject) => {
        if (!p) {
            console.error(page, 'page does not exist!');
            let tpl = defaults.templates.status['404'];
            if (tpl) {
                let doc = showError({
                    template: tpl,
                    title: '404',
                    message: 'The requested page cannot be found!'
                });
                resolve(doc);
            } else {
                reject();
            }
            return;
        }

        p(options).then((doc) => {
            // support suppressing of navigation since there is no dom available (page resolved with empty document)
            if (doc) {
                // if page is a modal, show as modal window
                if (p.type === 'modal') {
                    // defer to avoid clashes with any ongoing process (tvmlkit weird behavior -_-)
                    _.defer(presentModal, doc);
                } else { // navigate
                    // defer to avoid clashes with any ongoing process (tvmlkit weird behavior -_-)
                    _.defer(cleanNavigate, doc, replace);
                }
            }
            // resolve promise
            resolve(doc);
        }, (error) => {
            // something went wrong during the page execution
            // warn and set the status to 500
            if (error instanceof Error) {
                console.error(`There was an error in the page code. ${error}`);
                error.status = '500';
            }
            // try showing a status level error page if it exists
            let statusLevelErrorTpls = defaults.templates.status;
            let tpl = statusLevelErrorTpls[error.status];
            if (tpl) {
                showError(_.defaults({
                    template: tpl
                }, error.response));
                resolve(error);
            } else {
                console.warn('No error handler present in the page or navigation default configurations.', error);
                reject(error);
            }
        });
    });
}
function navigate ( page , options , replace ) { let p = Page . get ( page ) ; if ( _ . isBoolean ( options ) ) { replace = options ; } else { options = options || { } ; } if ( _ . isBoolean ( options . replace ) ) { replace = options . replace ; } console . log ( 'navigating... page:' , page , ':: options:' , options ) ; // return a promise that resolves if there was a navigation that was performed return new Promise ( ( resolve , reject ) => { if ( ! p ) { console . error ( page , 'page does not exist!' ) ; let tpl = defaults . templates . status [ '404' ] ; if ( tpl ) { let doc = showError ( { template : tpl , title : '404' , message : 'The requested page cannot be found!' } ) ; resolve ( doc ) ; } else { reject ( ) ; } return ; } p ( options ) . then ( ( doc ) => { // support suppressing of navigation since there is no dom available (page resolved with empty document) if ( doc ) { // if page is a modal, show as modal window if ( p . type === 'modal' ) { // defer to avoid clashes with any ongoing process (tvmlkit weird behavior -_-) _ . defer ( presentModal , doc ) ; } else { // navigate // defer to avoid clashes with any ongoing process (tvmlkit weird behavior -_-) _ . defer ( cleanNavigate , doc , replace ) ; } } // resolve promise resolve ( doc ) ; } , ( error ) => { // something went wrong during the page execution // warn and set the status to 500 if ( error instanceof Error ) { console . error ( ` ${ error } ` ) ; error . status = '500' ; } // try showing a status level error page if it exists let statusLevelErrorTpls = defaults . templates . status ; let tpl = statusLevelErrorTpls [ error . status ] ; if ( tpl ) { showError ( _ . defaults ( { template : tpl } , error . response ) ) ; resolve ( error ) ; } else { console . warn ( 'No error handler present in the page or navigation default configurations.' , error ) ; reject ( error ) ; } } ) ; } ) ; }
Navigates to the provided page if it exists in the list of available pages.

@inner
@alias module:navigation.navigate

@param  {String} page        Name of the previously created page.
@param  {Object} options     The options that will be passed on to the page during runtime.
@param  {Boolean} replace    Replace the previous page.
@return {Promise}            Returns a Promise that resolves upon successful navigation.
Navigates to the provided page if it exists in the list of available pages .