Home
Blog
Showcase
Community
Introduction
Overview
Introduction To TinaCMS
Getting Started
Using the Tina Editor
FAQ
Core Concepts
Content Modeling
Data Fetching
Visual Editing
Overview
React
Vue
Setting up the Router
Querying Content
Overview
Writing custom queries
Editing
Overview
Markdown & MDX
Block-based editing
Single Document Collections
Customizing Tina
Overview
Validation
Custom Field Components
Custom List Rendering
Format and Parse Input
Filename Customization
Before Submit function
Going To Production
Overview
Tina Cloud
Self-Hosted
Drafts
Overview
Draft Fields
Editorial Workflow
Guides
Overview
Framework Guides
Separate Content Repo
Querying Tina Content at Runtime
Internationalization
Migrating From Forestry
Further Reference
Overview
Config
Schema
The "tina" folder
The TinaCMS CLI
Media
Search
Content API
Tina's edit state
The "tinaField" helper
Self-Hosted Components

Setting up a Router for Visual Editing


Accessing contextual-editing from the CMS

At this point, when your editors go to /your-page-url in edit-mode, they will be able to edit content and see those changes reflected on the page, in real-time. Next, let's ensure users will be navigated to that same live-editing experience (instead of the basic editor experience) every time they click on a document in the CMS Document List.

To accomplish this, we will make use of the ui.router property on a collection.

The router Property

The router property is used by the CMS's Document List to navigate to a document's contextual editor rather than the basic editor.

router: ({ collection: Collection, document: Document }) => string | undefined

The router property is a function, that is run when a document is clicked within a Document List:

  • If router returns a string, the string is used as the document's route rather than the default.
  • If router returns undefined, the user is navigated to the document's basic editor.

This is an example using router.

const default defineConfig({
schema: {
collections: [
{
name: 'page',
label: 'Page',
path: 'content/page',
format: 'md',
ui: {
router: ({ document }) => {
// navigate to the home page
if (document._sys.filename === 'home') {
return '/'
}
// navigate to the about page
if (document._sys.filename === 'about') {
return `/about`
}
return undefined
},
},
fields: [
// An array of fields
],
},
{
label: 'Blog Posts',
name: 'post',
path: 'content/posts',
format: 'mdx',
ui: {
router: ({ document }) => {
// navigate to the post that was clicked
return `/post/${document._sys.filename}`
},
},
fields: [
// An array of fields
],
}
]
}
})

Now when a document is clicked in the CMS we will be re-directed to the page in the site with visual editing.

Summary

  • A piece of content can be made editable by running it through the useTina hook. In production, it returns the original data unchanged. In edit-mode, it returns the live data, which is updated as the user types in the sidebar.
  • Make use of the router property to automatically navigate to the contextual-editing experience from the CMS.
Previous
Visual Editing in Vue

Product

Showcase
TinaCloud
Introduction
How Tina Works
Roadmap

Resources

Blog
Examples
Support
Media

Whats New
TinaCMS
TinaCloud
Use Cases
Agencies
Documentation
Teams
Jamstack CMS
Benefits
MDX
Markdown
Git
Editorial Workflow
Customization
SEO
Comparisons
TinaCMS vs Storyblok
TinaCMS vs Sanity
TinaCMS vs DecapCMS
TinaCMS vs Contentful
TinaCMS vs Builder.io
TinaCMS vs Strapi
Integrations
Astro
Hugo
NextJS
Jekyll