Weaverse LogoWeaverse
All Articles
Paul Phan
2 mins read

React Router 7.13.1: URL Masking for Modal PDPs in Hydrogen

New unstable_mask API in React Router 7.13.1 enables shareable modal URLs. Perfect for product quick-view modals in Shopify Hydrogen.
React Router 7.13.1: URL Masking for Modal PDPs in Hydrogen
Table of Contents

React Router 7.13.1: URL Masking for Modal PDPs in Hydrogen


URL masking for modal navigation in React Router 7.13.1
URL masking for modal navigation in React Router 7.13.1

The Problem

You want a product quick-view modal that:

  • Opens on top of your collection page
  • Shows a shareable URL (/products/sneakers)
  • Keeps the collection visible in the background
  • Works with deep links and browser history

Until now, this required manual backgroundLocation management—a clunky pattern that felt like fighting the framework.

Route and URL strategy planning for shareable modal states
Route and URL strategy planning for shareable modal states

The Solution

React Router 7.13.1 introduces unstable_mask on <Link>. First-class URL masking for Framework/Data Mode.

// routes/collection.tsx
export default function Collection({ loaderData }) {
return (
<div className="collection-grid">
{loaderData.products.map((product) => (
<Link
key={product.id}
to={`/collection?product=${product.id}`} // Router state
unstable_mask={`/products/${product.handle}`} // Browser URL
>
<ProductCard product={product} />
</Link>
))}
{/* Modal overlay */}
{loaderData.modalProduct && (
<dialog open>
<ProductQuickView product={loaderData.modalProduct} />
</dialog>
)}
</div>
)
}

How It Works

  1. Router navigates to /collection?product=123 (internal state)
  2. Browser shows /products/sneakers (masked URL)
  3. Deep link /products/sneakers works normally (mask stripped on SSR)
  4. Back button closes modal, restores collection

Detecting Masked State

import { useLocation } from 'react-router'
function ProductModal() {
const location = useLocation()
// Are we in a modal context?
if (location.unstable_mask) {
return <ModalProduct />
}
// Direct navigation - full page
return <FullProductPage />
}

Hydrogen Use Cases

  • Modal PDPs from collection grids
  • Image galleries with shareable URLs
  • Cart quick-edit from checkout
  • Filter previews without navigation

Important Notes

  • Marked unstable - API may change before stabilization
  • SPA only - Mask removed during SSR (deep links work normally)
  • Requires React Router 7.13.1+ in your Hydrogen project

Upgrade

npm install react-router@latest

Reactions

Like
Love
Celebrate
Insightful
Cool!
Thinking

Join the Discussion

Never miss an update

Subscribe to get the latest insights, tutorials, and best practices for building high-performance headless stores delivered to your inbox.

Join the community of developers building with Weaverse.