<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mohammed Zaghloul on Medium]]></title>
        <description><![CDATA[Stories by Mohammed Zaghloul on Medium]]></description>
        <link>https://medium.com/@msalahz?source=rss-fd12c359e178------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zsuRvdH_65Q1xiz5rb_7Ow.jpeg</url>
            <title>Stories by Mohammed Zaghloul on Medium</title>
            <link>https://medium.com/@msalahz?source=rss-fd12c359e178------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 09:12:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@msalahz/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to Integrate View Transitions in TanStack Start: A Complete Guide]]></title>
            <link>https://medium.com/@msalahz/how-to-integrate-view-transitions-in-tanstack-start-a-complete-guide-89b82ce962dc?source=rss-fd12c359e178------2</link>
            <guid isPermaLink="false">https://medium.com/p/89b82ce962dc</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[tan-stack-router]]></category>
            <category><![CDATA[view-transition]]></category>
            <category><![CDATA[tanstack-start]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Mohammed Zaghloul]]></dc:creator>
            <pubDate>Wed, 14 Jan 2026 23:01:47 GMT</pubDate>
            <atom:updated>2026-01-14T23:01:47.322Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*c2lOSC2n3l87Do0OD-MQ_w.png" /></figure><p>Recently, I tried to integrate view transitions into my side project, and I was happy to find out that TanStack Start, the framework I’m using, already supports it. But the documentation was unclear on how to get it fully functional, so after some research, I managed to get it working and decided to share the guide with you. Hope you find it helpful.</p><h3>What Are View Transitions?</h3><p>The <a href="https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API">View Transitions API</a> is a modern browser feature that enables smooth, animated transitions between different views or states in your application. Instead of abrupt page changes, users experience fluid animations that make navigation feel more natural and polished.</p><p>TanStack Router has built-in support for this API, making it surprisingly straightforward to implement once you understand the pieces involved.</p><h3>The Integration Journey</h3><p>I’ll walk you through the exact steps I followed, from the simplest implementation to a fully customized solution with direction-aware slide animations.</p><h4>Step 1: Enable Basic View Transitions</h4><p>The quickest way to get started is to set defaultViewTransition to true in your router configuration. This enables a default cross-fade animation for all route transitions.</p><pre>// src/router.tsx<br>import { createRouter } from &#39;@tanstack/react-router&#39;<br>import { routeTree } from &#39;./routeTree.gen&#39;<br><br>export const getRouter = () =&gt; {<br>  const router = createRouter({<br>    routeTree,<br>    defaultViewTransition: true,<br>  })<br><br>  return router<br>}</pre><p>With just this single line, you get a subtle fade animation between pages. It’s a great starting point, but I wanted something more sophisticated-slide animations that reflect the navigation direction.</p><h4>Step 2: Add Custom CSS Keyframes</h4><p>To create custom animations like sliding effects, you need two things:</p><ol><li><strong>A named transition element</strong> — Assign a view-transition-name to the element you want to animate</li><li><strong>CSS keyframes</strong> — Define the actual animation behavior</li></ol><p>In your root layout component, wrap your content with a named transition element:</p><pre>// In your root layout (e.g., __root.tsx)<br>&lt;main className=&quot;[view-transition-name:main-content]&quot;&gt;{children}&lt;/main&gt;</pre><p>This tells the browser which element to capture and animate during transitions.</p><h4>Defining the Animations</h4><p>Add these keyframes to your stylesheet. I created both left and right slide animations:</p><pre>/* Slide Left Transition */<br>html:active-view-transition-type(slide-left) {<br>  &amp;::view-transition-old(main-content) {<br>    animation: 300ms cubic-bezier(0.4, 0, 0.2, 1) both slide-out-left;<br>  }<br>  &amp;::view-transition-new(main-content) {<br>    animation: 300ms cubic-bezier(0.4, 0, 0.2, 1) both slide-in-left;<br>  }<br>}<br><br>@keyframes slide-out-left {<br>  from {<br>    transform: translateX(0);<br>  }<br>  to {<br>    transform: translateX(-100%);<br>  }<br>}<br><br>@keyframes slide-in-left {<br>  from {<br>    transform: translateX(100%);<br>  }<br>  to {<br>    transform: translateX(0);<br>  }<br>}<br><br>/* Slide Right Transition */<br>html:active-view-transition-type(slide-right) {<br>  &amp;::view-transition-old(main-content) {<br>    animation: 300ms cubic-bezier(0.4, 0, 0.2, 1) both slide-out-right;<br>  }<br>  &amp;::view-transition-new(main-content) {<br>    animation: 300ms cubic-bezier(0.4, 0, 0.2, 1) both slide-in-right;<br>  }<br>}<br><br>@keyframes slide-out-right {<br>  from {<br>    transform: translateX(0);<br>  }<br>  to {<br>    transform: translateX(100%);<br>  }<br>}<br><br>@keyframes slide-in-right {<br>  from {<br>    transform: translateX(-100%);<br>  }<br>  to {<br>    transform: translateX(0);<br>  }<br>}</pre><p>The key insight here is the html:active-view-transition-type() selector-this allows you to apply different animations based on a &quot;type&quot; that you specify programmatically.</p><h4>Step 3: Configure Dynamic Transition Types</h4><p>This is where the magic happens. Instead of passing a boolean todefaultViewTransition, you can pass an object with a types function that determines which transition type to use based on navigation context.</p><pre>// src/router.tsx<br>import { createRouter } from &#39;@tanstack/react-router&#39;<br>import { routeTree } from &#39;./routeTree.gen&#39;<br><br>export const getRouter = () =&gt; {<br>  const router = createRouter({<br>    routeTree,<br>    defaultViewTransition: {<br>      types: ({ fromLocation, toLocation }) =&gt; {<br>        let direction = &#39;none&#39;<br><br>        if (fromLocation) {<br>          const fromIndex = fromLocation.state.__TSR_index<br>          const toIndex = toLocation.state.__TSR_index<br>          if (fromIndex !== toIndex) {<br>            direction = fromIndex &gt; toIndex ? &#39;right&#39; : &#39;left&#39;<br>          }<br>        }<br><br>        // Prevent animation when navigating to the same route<br>        if (fromLocation?.state.__TSR_index === toLocation?.state.__TSR_index) {<br>          direction = &#39;none&#39;<br>        }<br><br>        return [`slide-${direction}`]<br>      },<br>    },<br>  })<br><br>  return router<br>}</pre><h4>How It Works</h4><p>TanStack Router internally tracks route indices via __TSR_index. By comparing the indices of the source and destination routes, we can determine the navigation direction:</p><ul><li><strong>Higher index → Lower index</strong> = Going “back” = Slide right</li><li><strong>Lower index → Higher index</strong> = Going “forward” = Slide left</li><li><strong>Same index</strong> = No animation needed</li></ul><p>The returned array [&#39;slide-left&#39;] or [&#39;slide-right&#39;] maps directly to our CSS selectors html:active-view-transition-type(slide-left) and html:active-view-transition-type(slide-right).</p><h4>Step 4: Per-Link Customization (Optional)</h4><p>Sometimes you want specific links to behave differently from the global default. The viewTransition prop on Link components give you this control.</p><p>Force a specific animation regardless of navigation direction:</p><pre>// Always slide left when navigating to a post detail<br>&lt;Link<br>  to=&quot;/posts/$postId&quot;<br>  params={{ postId: post.id.toString() }}<br>  viewTransition={{ types: [&#39;slide-left&#39;] }}<br>&gt;<br>  {post.title}<br>&lt;/Link&gt;</pre><h4>Back Navigation</h4><p>For “back” links, you typically want the reverse animation:</p><pre>&lt;Link to=&quot;/posts&quot; viewTransition={{ types: [&#39;slide-right&#39;] }}&gt;<br>  Back to all posts<br>&lt;/Link&gt;</pre><h4>Dynamic Per-Link Logic</h4><p>You can also use a function for more complex scenarios, such as a “Next Post” button that determines a slide direction based on post-IDs:</p><pre>&lt;Link<br>  to=&quot;/posts/$postId&quot;<br>  params={{ postId: nextPost.id.toString() }}<br>  viewTransition={{<br>    types: ({ fromLocation }) =&gt; {<br>      const currentPostId = fromLocation?.pathname.match(/\/posts\/(\d+)/)?.[1]<br>      const nextPostId = nextPost.id.toString()<br>      return Number(nextPostId) &gt; Number(currentPostId)<br>        ? [&#39;slide-left&#39;]<br>        : [&#39;slide-right&#39;]<br>    },<br>  }}<br>&gt;<br>  Next Post<br>&lt;/Link&gt;</pre><p>View Transitions are supported in modern browsers:</p><pre>| Browser | Minimum Version |<br>|---------|-----------------|<br>| Chrome  | 111+            |<br>| Edge    | 111+            |<br>| Safari  | 18+             |</pre><p>For unsupported browsers, navigation works normally, just without animations. You can detect support programmatically:</p><pre>if (document.startViewTransition) {<br>  // View Transitions are supported<br>}</pre><h4>Key Takeaways</h4><ol><li><strong>Start simple</strong> — defaultViewTransition: true gets you basic fade transitions immediately</li><li><strong>Name your elements</strong> — Use view-transition-name to identify animatable content</li><li><strong>Define transition types</strong> — CSS selectors with active-view-transition-type() map to your programmatic types</li><li><strong>Use route indices</strong> — TanStack Router’s __TSR_index makes direction detection straightforward</li><li><strong>Override per-link</strong> — The viewTransition prop on Link gives fine-grained control</li></ol><h4>Resources</h4><ul><li><a href="https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#defaultviewtransition-property">TanStack Router Documentation: defaultViewTransition property</a></li><li><a href="https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#viewtransition">TanStack Router Documentation: View Transitions Navigation Options</a></li><li><a href="https://www.youtube.com/watch?v=LyKOB_xNXEY">YouTube Video: The Coolest TanStack Feature by Josef Bender</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API">MDN View Transitions API</a></li><li><a href="https://developer.chrome.com/docs/web-platform/view-transitions">Chrome Developers: View Transitions</a></li></ul><p><em>You can find the source code of this post on </em><a href="https://github.com/msalahz/ts-start-view-transition"><em>GitHub</em></a><em>.</em></p><p>I hope this guide saves you the hours I spent figuring this out. View transitions really elevate the user experience, and with TanStack Start’s built-in support, implementing them is more accessible than ever.</p><p>Feel free to reach out if you have questions or run into issues!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=89b82ce962dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>