Customizing the Routing

Customizing the Routing

Scrivito includes support for routing and the browsing history, so the Scrivito pages of your single-page application can be bookmarked and indexed, and visitors can use their browser’s back button.

Scrivito uses a simple routing scheme with three customizable URL forms:

URL formDescription
/Initially, when the homepage of a Scrivito-based website is first visited, the corresponding CMS object is automatically determined and rendered. As a default, the homepage is determined using the Obj.root method which finds the CMS object whose CMS path is “/”. You can customize the CMS object to act as the homepage using the homepage callback that can be set in the call to Scrivito.configure.
/slug-idFor pages without a permalink, the Scrivito SDK generates a SEO-friendly slug from the CMS object’s title and appends the CMS object ID to it (separated by a dash if the title isn’t empty). The slug is computed using the Obj#slug method which can be overridden for customizing URLs. Example:
https://www.mysite.net/my-cool-page-title-20ad1e5b3456b3ef
/permalinkA permalink is a usually human-readable identifier editors may assign to a page. Permalinks must be unique; Scrivito validates them to ensure this. Example:

https://www.mysite.net/blog

MethodPurpose
Scrivito.currentPageDetermines the CMS object representing the currently displayed page in order to access its attributes and render them, for example, or to have the current page displayed differently in an automatically generated navigation.
Scrivito.navigateToLets you navigate programmatically to a specific page.
Scrivito.urlForDetermines the URL of a given CMS object (Obj), Binary, or Link object.
Scrivito.useHistory For changing the routing scheme and for integrating router libraries such as React Router.