Skip to main content

URLs and routes

Studio shows your site inside the canvas, in an iframe, at your site's own address. So the address, and the route on your site that answers it, decide what Studio shows and what your visitors see. This topic explains how an address reaches a template, and how the canvas opens templates and sections.

Set up Studio takes you through the common case: Configure your project, Wire template preview routes, then Create a template. Each page in this topic covers one case in detail.

The example on this page is the Blog post template, previewing AI 101 at /blog/ai-101, and the Post hero section. The names come from the team blog.

Four URLs that are easy to mix up​

Studio and Contentstack use four different URLs.

URLWhat it isWhere it's set
Template URLThe pattern that decides which addresses show this templateOn the template, in Studio
Base URLThe domain in front of every address, such as https://www.example.comIn Contentstack, on each environment, one for each language
Custom Preview URLA stack setting that tells Live Preview and Visual Editor where each entry lives. Studio can take a Template URL from it.In Contentstack, under Settings, then Visual Experience, then Preview URL
Canvas URLThe one address where Studio opens sections for editingOn the Configuration tab of your Studio project settings

A visitor's address is the Base URL plus the path the Template URL produces. So https://www.example.com plus /blog/ai-101 gives https://www.example.com/blog/ai-101.

The production Base URL https://www.example.com plus the path /blog/ai-101, from /blog/{{entry.slug}}, gives https://www.example.com/blog/ai-101.

How an address becomes a template on your site​

Studio stores your templates, and your site serves them. One route on your site answers every address a template can have:

  1. A visitor's browser, or the Studio canvas, asks your site for /blog/ai-101.
  2. Your catch-all route passes that address to Studio as url. A route can also ask for a template by its UID.
  3. Studio finds the template whose URL matches, Blog post, and then the entry for the address, AI 101.
  4. <StudioComponent /> renders the Blog post template with AI 101.

The same route serves visitors and the canvas. <StudioComponent /> switches to editing when it runs inside Studio, so your route doesn't branch.

Outside Studio, your site reads published content. It reads drafts only when a Live Preview hash arrives in the address's query string, as it does on the canvas.

A visitor's browser and the Studio canvas both ask your site for /blog/ai-101. The catch-all route app/[[...slug]]/page.tsx passes the address to Studio as url, Studio finds the Blog post template and then the AI 101 entry, and StudioComponent renders them, as the page for the visitor and for editing on the canvas.

When several templates could match an address, the one with the most fixed text in its URL wins. Studio matches the address exactly, so capital letters and a trailing slash count. How Studio matches an address to a template explains the rules, and fixes each card the canvas shows about an address.

A route doesn't have to fetch by address. When your route already knows the template and the entry, it can ask for them by UID. Ways to fetch a template shows each way, and when it fits.

How the canvas opens a template​

When you open a template, the canvas loads your project's base URL and adds the Template URL, filled in from the preview entry. The base URL is the environment's URL for the project's language. You set both for the whole project in Settings, on the Configuration tab. In the Blog project, Environment is local and Language is English, so the base URL is http://localhost:3106. The Blog post template previewing AI 101 opens at http://localhost:3106/blog/ai-101.

The Configuration tab of the Blog project&#39;s settings, with Environment local, Language English - United States, Base URL http://localhost:3106 and Canvas URL /canvas.

To preview another environment or language without changing it for everyone, use Configuration in the canvas toolbar. Your pick is saved in your browser only. Reset puts the project's settings back in the dialog, and Save uses them again. See How the canvas Configuration dialog differs.

The canvas builds its address from three parts: the base URL http://localhost:3106 from the project's Configuration tab, with Environment local and Language English; the path /blog/ai-101 from the Blog post Template URL /blog/{{entry.slug}} filled in from AI 101; and Studio's query string. The canvas loads http://localhost:3106/blog/ai-101?cs-composable-studio=true and the rest, and your route receives it. For a template whose URL comes from the Custom Preview URL, the Alias picked in the canvas Configuration dialog gives the base URL instead.

How the base URL and the Template URL join​

Studio builds the address in two steps. It takes one / off the end of the base URL, if there is one. Then it adds the Template URL exactly as written, with nothing between them. Studio never adds a / of its own.

Base URLTemplate URLThe canvas opens
http://localhost:3106/blog/{{entry.slug}}http://localhost:3106/blog/ai-101
http://localhost:3106//blog/{{entry.slug}}http://localhost:3106/blog/ai-101, the same: the base URL's / is taken off
http://localhost:3106/blog/{{entry.slug}}http://localhost:3106blog/ai-101, a broken address
http://localhost:3106/http://localhost:3106/, your home page

So the / between the two always comes from the Template URL. Start every Template URL with /. Give your home page the Template URL /, because Studio doesn't accept an empty one. Your site works the same way: your route passes paths that start with /, such as /blog/ai-101, and Studio matches them exactly. See Plan your Template URLs.

When the Custom Preview URL lists base URLs, a template whose URL comes from it opens on one of them instead, such as Local. Aliases are base URLs listed in the Custom Preview URL, and you pick one in the Configuration dialog. See Use a Custom Preview URL with Studio.

Studio also adds query parameters of its own to the address, such as cs-composable-studio=true. They tell your site that it's inside Studio, and which template and entry to show. Your route passes the query string on to Studio as it arrived, and doesn't read it. On the server, code that rebuilds the address without its query string drops them. See Keep Studio's query string.

How the canvas opens a section​

A section is a part you place inside templates. Visitors never open it on its own, so it has no URL.

Studio opens every section at the base URL plus the project's Canvas URL, such as http://localhost:3106/canvas. It's one address for every section, and it's only for editing. The query string names the section, and <StudioCanvas /> reads which section to show from it.

You set the Canvas URL in the project's Settings, on the Configuration tab, in Canvas URL, under Base URL in the screenshot above. It's a path, such as /canvas, and it's saved on the project for everyone. Changing Canvas URL in the canvas Configuration dialog changes it for everyone too, unlike the environment and language there. See Configure your project.

The Configuration tab of the Blog project&#39;s settings, with Canvas URL /canvas and its tooltip open, reading &quot;Used by Section Compositions to open, preview, build, and deploy in Studio.&quot;

So the Canvas URL is the one home where every section opens for editing. Outside Studio's iframe, <StudioCanvas /> renders nothing, so visitors never see a section there. Keep the route on any site whose address Studio opens.

Your site needs a route of its own at the Canvas URL, never the catch-all. If the catch-all claims the address, the canvas shows a page or nothing instead of the section. See Mount the section preview route.

Studio never matches an address against sections, inside Studio or out. A section reaches visitors in one of two places:

  • On a template. A section appears on your live site wherever a deployed template uses it, such as Post hero on Blog post.
  • On a page your code owns. Any page can fetch a section by its Section UID and render it, with no template around it. See Use sections in pages outside Studio.

A section also has no SEO fields. Those belong to the template that holds it.

On the left, the canvas opens http://localhost:3106/canvas with Studio's query string naming Post hero, and StudioCanvas on your route at /canvas renders the Post hero section for editing. On the right, a page your code owns fetches Post hero by its Section UID, post_hero, and renders it with no template around it.

Pages in this topic​

Report a problem with this page