Skip to content

Commit 477063f

Browse files
committed
content: blogpost
1 parent 65a317a commit 477063f

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Deep Link Configuration: Achieving a Global Parameter Observer in React
2+
3+
Have you ever wanted to share a link that not only takes a user to a specific page but also **configures the entire site's vibe** the moment they arrive?
4+
5+
In the latest update to **Fezcodex**, we implemented a global "Deep Link Configuration" system. This allows us to set the theme, reading modes, and other preferences directly via URL parameters—and then make those parameters vanish so the user is left with a clean address bar.
6+
7+
## The Challenge
8+
9+
Standard routing (like `/set-theme/luxe`) is clunky. It requires a dedicated route, a redirect, and often a full page reload which breaks the immersion. We wanted something that:
10+
1. Works on **any** URL.
11+
2. Updates global state (not just one page).
12+
3. Leaves the URL clean after consumption.
13+
14+
## The Implementation
15+
16+
We achieved this by placing a **URL Observer** inside our `VisualSettingsContext`. Since this context wraps the entire application, it's one of the first things to mount.
17+
18+
### 1. Intercepting Parameters
19+
Inside a `useEffect` hook, we use the native `URLSearchParams` API to look for specific "Reserved Keywords":
20+
21+
```javascript
22+
const params = new URLSearchParams(window.location.search);
23+
const themeParam = params.get('fezTheme'); // Looks for ?fezTheme=...
24+
```
25+
26+
### 2. Updating Persistent State
27+
If a valid parameter is found, we trigger our state update functions. Because we use **Persistent State** (synced with `localStorage`), the change is instantly saved for the user's future visits.
28+
29+
### 3. The Vanishing Act
30+
To maintain a premium user experience, we don't want `?fezTheme=luxe` sitting in the address bar forever. We use the **Browser History API** to strip the parameters without triggering a reload:
31+
32+
```javascript
33+
const newUrl = window.location.pathname + window.location.hash;
34+
window.history.replaceState({}, '', newUrl);
35+
```
36+
37+
## Try it Yourself
38+
39+
Experience the "magic" by clicking these links (they will open in a new tab and configure your session instantly):
40+
41+
- **[Switch to Luxe Theme Globally](?fezTheme=luxe)**
42+
- **[Switch to Brutalist Theme Globally](?fezTheme=brutalist)**
43+
- **[Set Blog Mode to Terminal (Emerald)](?fezBlogMode=terminal-green)**
44+
- **[Set Blog Mode to Editorial (Default)](?fezBlogMode=editorial)**
45+
46+
## Why This Matters
47+
48+
This pattern is incredibly powerful for:
49+
- **Marketing:** Sharing specific themes or "night modes" in social media previews.
50+
- **A/B Testing:** Directing segments of users to different visual experiences.
51+
- **Accessibility:** Providing one-click links that enable "Reduce Motion" or high-contrast modes for users who need them.
52+
53+
It’s a simple solution that bridges the gap between static URLs and dynamic application states.
54+
55+
## Sidenote: Solving the "Ghost Navbar" with `createPortal`
56+
57+
During the development of the Luxe expansion, we hit a classic CSS stacking context issue. Even with a `z-index` of 1000, our new high-fidelity modals were appearing *underneath* the persistent Navbar and Sidebar. This happens because the modals were nested deep within the page content, and their "max height" was being capped by the parent container's layout logic.
58+
59+
We solved this using **React Portals** (`createPortal`).
60+
61+
Instead of rendering the modal where it's declared, we "teleport" it to the very end of the `document.body`. This makes the modal a direct child of the body, allowing it to escape all parent constraints and sit physically on top of every other element on the site. Now, when you enlarge a specimen or expand code, the immersion is absolute—no ghost layout elements required.
62+
63+
Happy Deep Linking!

public/posts/posts.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
[
2+
{
3+
"slug": "deep-link-configuration-with-url-parameters",
4+
"title": "Deep Link Configuration: Achieving a Global Parameter Observer in React",
5+
"date": "2026-01-21",
6+
"updated": "2026-01-21",
7+
"description": "How to implement a global URL parameter observer that silently updates application state and cleans up the address bar for a seamless user experience.",
8+
"tags": ["react", "webdev", "url-parameters", "ux", "browser-api", "frontend", "dev"],
9+
"category": "dev",
10+
"filename": "deep-link-configuration-with-url-parameters.txt",
11+
"authors": ["fezcode"],
12+
"image": "/images/asset/url-magic.webp"
13+
},
214
{
315
"slug": "introducing-fezluxe-refined-architectural-elegance",
416
"title": "Introducing Fezluxe: A Study in Refined Architectural Elegance",

0 commit comments

Comments
 (0)