Creating Custom URL Routes in Sapper/Svelte like Next.js

4 replies
Last updated: Apr 29, 2020
Question for those familiar with Svelte/Sapper and Next – 

Sanity’s Next.js starter allows you to define custom URL routes in the Studio, and associate pages to these.
Is this also possible using Sapper or is it a special ability of Next? Thanks
Apr 28, 2020, 1:00 PM
Hi
user Y
- It looks like you did a lot of the heavy lifting on both the Next and Sapper starter projects. Do you have any thoughts on this?
Apr 28, 2020, 9:15 PM
It should work in any framework, since it‘s mostly about how you query the data. You use Sappers route params in groq to find the correct route document, then you join the referenced page, so, something along the lines of this:
*[_type == "route" && slug.current == $slug]{
  ...,
  page->
}

Apr 28, 2020, 9:57 PM
Thanks
user Y
, I appreciate it - I’ll try that out
Apr 29, 2020, 4:42 PM
I’m still getting my hands around Sanity and Sapper - to double-check, is the snippet above in the context of the Studio schemas or Sapper’s configuration?
Apr 29, 2020, 4:44 PM

Sanity.io – build remarkable experiences at scale

Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.