navigate - Methods - Author API

Author API Methods

navigate()

Navigates the Author API to the specified location. The navigation is immediate and any unsaved changes in the current view will be lost.

You would want to use this method so that you can advance to a new view in your application, for example.

Note Navigating to the same location (including search parameters) does not refresh the data. To refresh the content, use the refreshSearch method instead.

Examples

// Item Examples
// Navigate to an existing Item (or a new one with the provided reference, if it doesn't exist)
var canNavigate = authorApp.navigate('items/' + myItemReference);
console.log(canNavigate);

// Navigate to the Item list
var canNavigate = authorApp.navigate('items');
console.log(canNavigate);

// Navigate to the Item list with specific hierarchies
var canNavigate = authorApp.navigate('items/search/' + encodeURIComponent(
    JSON.stringify({
        "browse": {
            "hierarchy": {
                "reference": "CCSS",
                "tags": [
                    {
                        "type": "Common Core Topic",
                        "name": "The Number System",
                        "label": "The Number System"
                    },
                    {
                        "type": "Common Core State Standard",
                        "name": "Geometry",
                        "label": "Geometry"
                    }
                ]
            },
            "tags": [
                {
                    "type": "course",
                    "name": "Introduction to algebra"
                }
            ]
        }
    })
));
console.log(canNavigate);

// Navigate to show unpublished Items
var canNavigate = authorApp.navigate('items/search/' + encodeURIComponent('{ "status": "unpublished" }'));
console.log(canNavigate);

// Navigate to the Questions tile view
var canNavigate = authorApp.navigate('items/' + myItemReference + '/widgets/new');
console.log(canNavigate);

// Navigate to the Features tile view
var canNavigate = authorApp.navigate('items/' + myItemReference + '/widgets/new/' + encodeURIComponent('{ "widgetType": "features" }'));
console.log(canNavigate);

// A common way to use navigate is to load straight into the widget editor with a particular template.
// See the knowledge base for a list of available template references.
// Navigate to create a new multiple choice Question
var canNavigate = authorApp.navigate('items/' + myItemReference + '/widgets/new/' + encodeURIComponent(
    JSON.stringify({
        widgetTemplate: {
            template_reference: '9e8149bd-e4d8-4dd6-a751-1a113a4b9163'
        }
    })
));
console.log(canNavigate);

// Below is an example of how to initialize directly to any widget template, for example, "Calculator"
function goToWidgetEdit(myItemReference, widgetType, templateName) {
    return authorApp.navigate(
        'items/' + myItemReference + '/widgets/new/' + encodeURIComponent(JSON.stringify({
            widgetType: widgetType,
            widgetTemplate: {
                template_reference: templateName
            }
        }))
    );
}
// Then add a calculator feature
goToWidgetEdit('my - item - reference', 'features', '532767d1-40e7-47e4-be81-ec5cdbfb5fd8');

// Activity Examples
// Navigate to a new Activity
var canNavigate = authorApp.navigate('activities/new');
console.log(canNavigate);

// Navigate to an existing Activity (or a new one with the provided reference, if it doesn't exist)
// Note this can be used to navigate to any type of Activity (Standard, Adaptive, or Random)
var canNavigate = authorApp.navigate('activities/' + myActivityReference);
console.log(canNavigate);

// Navigate to a new Random Activity
var canNavigate = authorApp.navigate('activities/new/random');
console.log(canNavigate);

// Navigate to a new Adaptive Activity
var canNavigate = authorApp.navigate('activities/new/adaptive');
console.log(canNavigate);

Arguments

  • location string

    The view to navigate to, including all required references and URL parameters.

    Note All data in the location string should be URI encoded.

Return value

Type boolean

Before executing, this method will check if the new location is valid and is not the current location.

Returns true if it is possible to navigate.

Returns false if unable to navigate.

Note The return value only indicates whether it is possible to navigate to a new location based on the validation. It does not indicate that the navigation has completed.

Caveats

Navigating multiple times in quick succession can have unintended side effects. It is recommended to listen for a relevant event to fire before navigating again.

Versioning

Version added: v2022.1.LTS

Related articles

Was this article helpful?

Did you arrive here by accident? If so, learn more about Learnosity.