Liquid Tutorial

routes Object

Source: Coding with Robby

Canonical Store URLs

routes provides locale- and market-aware URL paths. Hardcoding /cart or /account breaks when Shopify adds language prefixes (/en/cart) or custom routing. Always use routes for internal links.

  • routes.root_url — homepage
  • routes.cart_url, routes.cart_add_url, routes.cart_change_url
  • routes.account_url, routes.account_login_url, routes.account_logout_url, routes.account_register_url
  • routes.collections_url, routes.all_products_collection_url
  • routes.search_url — /search with ?q= parameter
  • routes.predictive_search_url — AJAX search endpoint
Navigation with routes
<nav>
  <a href="{{ routes.root_url }}">Home</a>
  <a href="{{ routes.collections_url }}">Shop</a>
  <a href="{{ routes.cart_url }}">Cart ({{ cart.item_count }})</a>
  <a href="{{ routes.account_url }}">Account</a>
</nav>

<form action="{{ routes.search_url }}" method="get" role="search">
  <input type="search" name="q" placeholder="Search courses…">
</form>
Note: routes.cart_add_url is the form action target when not using {% form 'product' %} — prefer the form tag for CSRF protection.