examples/HTML StarterKit/lib/durandal/js/plugins/router.js
function handleGuardedRoute(activator, instance, instruction) {
            var resultOrPromise = router.guardRoute(instance, instruction);
            if (resultOrPromise) {
                if (resultOrPromise.then) {
                    resultOrPromise.then(function(result) {
                        if (result) {
                            if (system.isString(result)) {
                                redirect(result);
                            } else {
                                activateRoute(activator, instance, instruction);
                            }
                        } else {
                            cancelNavigation(instance, instruction);
                        }
                    });
                } else {
                    if (system.isString(resultOrPromise)) {
                        redirect(resultOrPromise);
                    } else {
                        activateRoute(activator, instance, instruction);
                    }
                }
            } else {
                cancelNavigation(instance, instruction);
            }
        }
function handleGuardedRoute(activator, instance, instruction) {
            var resultOrPromise = router.guardRoute(instance, instruction);
            if (resultOrPromise) {
                if (resultOrPromise.then) {
                    resultOrPromise.then(function(result) {
                        if (result) {
                            if (system.isString(result)) {
                                redirect(result);
                            } else {
                                activateRoute(activator, instance, instruction);
                            }
                        } else {
                            cancelNavigation(instance, instruction);
                        }
                    });
                } else {
                    if (system.isString(resultOrPromise)) {
                        redirect(resultOrPromise);
                    } else {
                        activateRoute(activator, instance, instruction);
                    }
                }
            } else {
                cancelNavigation(instance, instruction);
            }
        }
function handleGuardedRoute ( activator , instance , instruction ) { var resultOrPromise = router . guardRoute ( instance , instruction ) ; if ( resultOrPromise ) { if ( resultOrPromise . then ) { resultOrPromise . then ( function ( result ) { if ( result ) { if ( system . isString ( result ) ) { redirect ( result ) ; } else { activateRoute ( activator , instance , instruction ) ; } } else { cancelNavigation ( instance , instruction ) ; } } ) ; } else { if ( system . isString ( resultOrPromise ) ) { redirect ( resultOrPromise ) ; } else { activateRoute ( activator , instance , instruction ) ; } } } else { cancelNavigation ( instance , instruction ) ; } }
Inspects routes and modules before activation. Can be used to protect access by cancelling navigation or redirecting.
@method guardRoute
@param {object} instance The module instance that is about to be activated by the router.
@param {object} instruction The route instruction. The instruction object has config, fragment, queryString, params and queryParams properties.
@return {Promise|Boolean|String} If a boolean, determines whether or not the route should activate or be cancelled. If a string, causes a redirect to the specified route. Can also be a promise for either of these value types.
Inspects routes and modules before activation . Can be used to protect access by cancelling navigation or redirecting .