Discussion about implementing routing in Sanity plugins and creating custom pages in Sanity Studio.

10 replies
Last updated: Jun 2, 2021
Anyone know of any sanity plugins that implements routing? Would like to see how it's done. Is using
@sanity/state-router
the recommended way?
AI Update

Based on the discussion you linked and the recent Sanity Studio v3 changes, here's what you need to know about implementing routing in Sanity plugins:

Using @sanity/state-router and the Router API

Yes, the Router API (which includes @sanity/state-router concepts) is the recommended way to handle routing in Sanity Studio plugins. As of Studio v3.81.0 (March 2025), there have been significant improvements to the Router API.

Example Implementation

The best reference is the plugin-template-tool-with-routing template mentioned in the community discussion. This shows how to:

  1. Create a custom tool/plugin that registers routes
  2. Use the router components for navigation:
    • StateLink - for navigating with params
    • IntentLink - for subpages/intents
    • Link - for basic navigation back to your plugin's base route

Recent Router API Improvements (v3.81.0)

The Router API now has better support for stickyParams via the useRouter hook:

const router = useRouter()

// Navigate with sticky params
router.navigate({
  stickyParams: {paramKey: 'paramValue'}, 
  replace: false
})

// Or combine with state updates
router.navigate({
  stickyParams: {paramKey: 'paramValue'},
  state: {
    stateKey: 'stateValue'
  }
})

Note: navigateStickyParams from sanity/router is now deprecated - use the navigate method with options instead.

Creating Custom Pages

To create a custom page at a route like /mycustompage (similar to /desk), you need to:

  1. Create a custom tool plugin
  2. Register it in your sanity.config.ts
  3. The plugin will automatically get its own route
  4. You can render any React component/UI you want within that tool

The community member in your linked discussion confirmed this is possible - you create a plugin tool that renders custom UI and handles its own routing internally.

Finding More Examples

Unfortunately, as noted in the discussion, documentation is limited. Your best bet is to:

The Router API is actively being improved, so keep an eye on Studio changelogs for new routing features!

ok based on this I have something https://github.com/sanity-io/plugin-template-tool-with-routing/blob/master/template/MyTool.js
But I can't work out how to link back to the base plugin page.
StateLink
works with params,
IntentLink
works with subpages. Say my base plugin is at
/foobar-plugin
and i've navigated to
/foobar-plugin/:someId
how do i provide a link back to
/foobar-plugin
ok solved, there's a
Link
component
`<Link href={
/foobar-plugin
}>Dashboard</Link>` for anyone wondering
user J
Do you think that by this concept we can add an custom page in sanity studio ? or am i misunderstanding this concept.
In short i want in my sanity studio an page like
myapp.seedling.studio/mycustompage
just like we have
myapp.seedling.studio/desk
. Is it possible buddy ?
user J
Yeah it’s possible. It’s called a plug-in. Some info here but it's not extensive. I've had to hunt around the code to work out how to do some things. https://www.sanity.io/docs/plugins
user J
Okay thanks for the consent Jordie, really appreciate it. I got your point...moreover like are you trying to say that i need to creat my own plugin tool and render custom UI on that path?? Actually bit confused, it would be very much helpfull if you redirect me to specific docs or blog or solution.
user J
Okay thanks for the consent Jordie, really appreciate it. I got your point...moreover like are you trying to say that i need to creat my own plugin tool and render custom UI on that path?? Actually bit confused, it would be very much helpfull if you redirect me to specific docs or blog or solution.
Question 1 - I want in my Sanity studio, an page like 
myapp.seedling.studio/mycustompage
 just like we have 
myapp.seedling.studio/desk
 . Is it possible  ? Question-2 - For example, On that page i want my own UI and i will be having an button there for example. Is this scenaio possible .??
user J
Basically i need this like on that page i would be doing some other react stuff. Is this possible ?
Param I don't work for Sanity, just another community member. I haven't been able to find many docs or blogs on how to do it. There's stuff at the link I showed you. If you create your own plugin it will create a new page in sanity where you can put a custom react component and do what you want.

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?