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

// Navigate to an Item
var canNavigate = authorApp.navigate('item/' + 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');

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 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?