Way to get all routes programmatically?

Way to get all routes programmatically?

bensenescu
Shopify Partner
2 0 0

Hello,  I am building an app where I'd like to get all the routes for a shopify store programmatically. 


Below are some things I tried and possible solutions - If there is a better way to get all routes, that would be amazing, thanks!

 

Some things that are close, but not what I'm looking for:

 

Possible Solution

I think some combination of the sitemap + routes object + getting all pages and policies via the api may work, but seems error prone.


Also, I feel like there may be a way to do it with the theme code, but I'm not sure how.

Reply 1 (1)

DaisyVo
Shopify Partner
4460 499 594

Hi @bensenescu 

I see you're trying to get ahold of all the routes in your Shopify store programmatically for your app. That's a great question, and while there isn't a single, built-in method, I can walk you through some options to achieve this:

Why the Built-in Options Won't Work:

  • Sitemap.xml: This is a good starting point, but it only captures SEO-relevant routes, not everything on your store.
  • routes Object: This built-in Liquid object offers a fixed list and isn't what you need for a complete picture.

Possible Solutions (and Their Quirks):

1-Combining Sitemap + API + Theme Code (Tricky but Feasible):

  • You're on the right track! This approach involves:
    • Using the sitemap for SEO routes.
    • Querying the Shopify Admin API for pages and policies (these have routes too).
    • Potentially digging into your theme code to identify dynamic routes (be cautious here, theme structures can vary).

2-This can be a bit error-prone and requires juggling multiple data sources.

3-Shopify App Options (Explore with Caution):

  • Some Shopify apps claim to help with managing custom social media icons. While their core function might be different, some might offer functionalities that could be adapted to route discovery. However, proceed with caution and thoroughly research any app before installing it.

Here's My Recommendation:

The first approach (combining sitemap, API, and theme code) can work, but it requires a bit of finesse. If you're comfortable with code and Shopify's API, it's definitely doable. However, if you're looking for a simpler solution, consider these alternatives:

  • Focus on Core Functionality: Can you achieve what you want in your app by focusing on the most important routes instead of trying to capture everything?
  • Explore Alternative Approaches: Is there another way to achieve your app's goal without needing all routes? Maybe there's another data point you can use.

Ultimately, the best approach depends on your specific needs.

If you decide to go the coding route and need further guidance on the API or theme exploration, feel free to ask! I'm happy to help you dig deeper.

In the meantime, here are some resources that might be helpful:

Best regards,

Daisy.






Please let us know if our reply is helpful by giving it a Like or marking it as a Solution!

Avada SEO & Image Optimizer - The #1 SEO solution