Pages
Tune Me In uses Shopify Hydrogen’s file-based routing system. Pages are defined as.server.jsx files in the src/pages/ directory.
File-Based Routing
Hydrogen automatically creates routes based on your file structure:Dynamic Routes
Files with brackets[handle] create dynamic routes that accept parameters:
[handle].server.jsx- Matches any single segment[...slug].server.jsx- Matches multiple segments (catch-all)
Creating a Basic Page
Add navigation links
Link to your new page from the header or other components:
src/components/Header.server.jsx
Dynamic Pages with Sanity CMS
Tune Me In fetches content from Sanity CMS using theuseSanityQuery hook:
src/pages/products/[handle].server.jsx
Collection Pages
Collection pages display lists of products with pagination:src/pages/collections/[handle].server.jsx
Homepage
The homepage (Index.server.jsx) typically features multiple sections:
src/pages/Index.server.jsx
Server-Side Rendering
All pages in Hydrogen are server-rendered by default:- Fast initial page loads - HTML is generated on the server
- SEO-friendly - Content is available to search engines
- Progressive enhancement - Works without JavaScript
Handling 404 Errors
Create aNotFound component for missing pages:
src/components/NotFound.server.jsx
Best Practices
Keep pages server-rendered
Keep pages server-rendered
Pages should always be
.server.jsx files. Move interactivity to client components.Use proper SEO
Use proper SEO
Always include the
Seo component with relevant metadata:Handle loading states
Handle loading states
Consider showing loading indicators while data is being fetched.
Implement proper error handling
Implement proper error handling
Always check if data exists before rendering and show appropriate error pages.
Next Steps
Product Listings
Learn how to build product listing and detail pages
Portable Text
Add rich editorial content with Portable Text