Public Method Author API

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.

Examples

function goToItem (reference) {
    return authorApp.navigate('item/' + reference);
}
function goToItemList () {
    return authorApp.navigate('items');
}
function gotToItemListWithHierarchies () {
    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"}
            ]
        }
    })));
}
function showUnpublishedItems () {
    return authorApp.navigate(
        'items/search/' + encodeURIComponent('{"status":"unpublished"}')
    );
}
// The following are examples of navigating to different sections of the Tile view.
function goToWidgetsTileView (itemReferenceOrNew) {
    return authorApp.navigate(
        'items/' + itemReferenceOrNew + '/widgets/new'
    )
}
function goToFeaturesTileView (itemReferenceOrNew) {
    return authorApp.navigate(
        'items/' + itemReferenceOrNew + '/widgets/new/' + encodeURIComponent('{"widgetType":"features"}')
    )
}
// One way to use navigate is for loading straight into the widget editor with a particular template.
// See the knowledge base for a list of available template references.
function createMultipleChoiceQuestion (itemReferenceOrNew) {
    return authorApp.navigate('items/' + itemReferenceOrNew + '/widgets/new/' + encodeURIComponent(JSON.stringify(
    {
        widgetTemplate: {
        template_reference: '9e8149bd-e4d8-4dd6-a751-1a113a4b9163'
        }
    })));
}
// Below is an example of how to initialize directly to any widget template (e.g. "Calculator"):
function goToWidgetEdit (itemReferenceOrNew, widgetType, templateName) {
    return authorApp.navigate(
        'items/' + itemReferenceOrNew + '/widgets/new/' + encodeURIComponent(JSON.stringify({
            widgetType: widgetType,
            widgetTemplate: {
            template_reference: templateName
            }
        }))
    )
}
// Add a calculator feature.
goToWidgetEdit('my - item - reference', 'features', '532767d1-40e7-47e4-be81-ec5cdbfb5fd8');

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

boolean

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

Returns true if it's 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