<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: 강재구</title>
    <description>The latest articles on DEV Community by 강재구 (@ash9river).</description>
    <link>https://dev.to/ash9river</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3627551%2F0e34837e-54f1-4fb9-978b-9d59ae38e7b4.png</url>
      <title>DEV Community: 강재구</title>
      <link>https://dev.to/ash9river</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ash9river"/>
    <language>en</language>
    <item>
      <title>Type-Safe Routing in React Without Redefining Routes (No Giant Constant Objects)</title>
      <dc:creator>강재구</dc:creator>
      <pubDate>Mon, 24 Nov 2025 15:09:07 +0000</pubDate>
      <link>https://dev.to/ash9river/type-safe-routing-in-react-without-redefining-routes-no-giant-constant-objects-50dg</link>
      <guid>https://dev.to/ash9river/type-safe-routing-in-react-without-redefining-routes-no-giant-constant-objects-50dg</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;The reason I ended up writing this post started from pure coincidence.&lt;/p&gt;

&lt;p&gt;While browsing through &lt;a href="https://velog.io/@rjw0907/a" rel="noopener noreferrer"&gt;technical blogs(sorry its korean ref)&lt;/a&gt;, I saw an article that made me think about path auto-completion.&lt;/p&gt;

&lt;p&gt;When I first read the post, I genuinely thought it was impressive.&lt;/p&gt;

&lt;p&gt;But there were parts I couldn’t immediately wrap my head around, and I kept wondering whether there was room for improvement.&lt;/p&gt;

&lt;p&gt;In the projects I had worked on before, I didn’t even have path auto-completion—&lt;br&gt;
I didn’t even have type safety.&lt;br&gt;
Whenever I had to navigate the user, I simply typed the route manually, almost like hand-writing it each time.&lt;/p&gt;

&lt;p&gt;Because of that, whenever a route changed, I had to update every single reference.&lt;br&gt;
Most of the time I didn’t even remember where those references were, and this inevitably caused bugs over and over again.&lt;/p&gt;

&lt;p&gt;So I decided that I needed path auto-completion and type safety of my own.&lt;/p&gt;

&lt;p&gt;But I wasn’t satisfied with applying the blog’s solution as it was.&lt;/p&gt;

&lt;p&gt;Not to criticize it, but I didn’t like the idea of redefining every route inside a single giant object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// the post&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;RoutePath&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;root&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;pathname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;userProfile&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;pathname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/user/:userId&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;commentDetail&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;pathname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/note/:noteId/comment/:commentId&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;notes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;pathname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/note&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;search&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;POPULARITY&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;UPDATED&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;userNotes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;pathname&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/user/:userId/notes&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;search&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;category&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;STUDY&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;WORK&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;PERSONAL&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first thing I thought deeply about was:&lt;br&gt;
How can I design this in a general-purpose way?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This is actually something I realized after completing the architecture,&lt;br&gt;
but redefining the root path makes no sense.&lt;br&gt;
If &lt;strong&gt;navigation&lt;/strong&gt; produced bugs in the past because of manually typed paths,&lt;br&gt;
then after the root is redefined, the new definition becomes the next &amp;gt;reason for bugs.&lt;br&gt;
Debugging becomes easier, but the fundamental cause remains unsolved.&lt;br&gt;
And it violates DRY as well.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I kept thinking about this on the train, at home, and even before sleeping.&lt;/p&gt;

&lt;p&gt;The next day, the first thing I did was run simulations.&lt;/p&gt;

&lt;p&gt;I listed out possible route patterns.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/
/a/b/c
/a/:b/c
/a/b/:c
/a/:b/c/:d
...
/a/:b/c/:d/e/:f/g/:h/.../x/:y/z
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Honestly… it was overwhelming.&lt;/p&gt;

&lt;p&gt;Then I came across &lt;a href="https://jeongyunlog.netlify.app/develop/typescript/typescript-autocomplete/" rel="noopener noreferrer"&gt;another article&lt;/a&gt;.(sorry also korean ref)&lt;/p&gt;

&lt;p&gt;This article defined route paths using constant unions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;ROUTE_PATH&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;root&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;Home&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/home&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;Dashboard&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/home/dashboard&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;MyPage&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/my-page&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At first, I thought about structuring my routing like Next.js App Router&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// my prototype&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;appRoutes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;root&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;home&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;homeRoutes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;dashBoard&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;dashBoardRoutes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And I imagined referencing routes like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ROUTE.APP
ROUTE.APP.HOME.DIARY.DIARYDETAIL.EDIT
ROUTE.APP.DASHBOARD
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Conceptually, it didn’t seem bad.&lt;/p&gt;

&lt;p&gt;But once I started actually creating folders and dozens of &lt;code&gt;index.ts&lt;/code&gt; files…&lt;br&gt;
I realized this approach made no sense.&lt;/p&gt;

&lt;p&gt;I had to solve the following three issues.&lt;/p&gt;
&lt;h2&gt;
  
  
  Expected Problems
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. Unpredictable route key structures
&lt;/h3&gt;

&lt;p&gt;For example, pages like &lt;code&gt;/diary/:diaryId/edit&lt;/code&gt; either required defining separate route objects&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;diaryEditRoutes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;edit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/edit&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or duplicating path definitions inside the same object&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;diaryRoutes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;root&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/diary&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;diaryDetail&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/diary/:diaryId&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;edit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/diary/:diaryId/edit&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both approaches are bad.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Forcing parameters in routes like &lt;code&gt;/a/:b/c/:d/&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;Yes, routes that start with &lt;code&gt;:&lt;/code&gt; enforce parameters,&lt;br&gt;
but adding flags like &lt;code&gt;isNeedParams&lt;/code&gt; felt ridiculous.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. When routes change, every redefined route must be updated manually
&lt;/h3&gt;

&lt;p&gt;Using &lt;code&gt;createBrowserRouter&lt;/code&gt; means:&lt;br&gt;
Once the real route tree changes, your manually redefined route constants become outdated immediately.&lt;/p&gt;


&lt;h2&gt;
  
  
  So What now?
&lt;/h2&gt;

&lt;p&gt;It felt like an endless chain of absurd situations.&lt;br&gt;
There was no silver bullet.&lt;br&gt;
So I decided to search for the &lt;strong&gt;most general-purpose&lt;/strong&gt; solution possible.&lt;/p&gt;

&lt;p&gt;The first step was dissecting the TypeScript types of &lt;code&gt;react-router-dom&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I had been using &lt;code&gt;RouteObject&lt;/code&gt;, and I wondered: what exactly is &lt;code&gt;DataRouteObject&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;I remembered reading documentation around a year ago saying:&lt;br&gt;
“Use the data API.”&lt;/p&gt;

&lt;p&gt;The classic &lt;code&gt;&amp;lt;Route&amp;gt;&lt;/code&gt;-style routing is still everywhere&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"/"&lt;/span&gt; &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Root&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt; &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"dashboard"&lt;/span&gt; &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Dashboard&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="p"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nc"&gt;Route&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But I usually use the newer approach:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;router&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;createBrowserRouter&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;element&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Root&lt;/span&gt; &lt;span class="o"&gt;/&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;loadRootData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I checked my package.json:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"react-router"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"6"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"react-router-dom"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"6"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But something felt off, so I checked again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm list react-router-dom
└── react-router-dom@6.30.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It was actually 6.30.0, meaning data API support was available.&lt;/p&gt;

&lt;p&gt;After analyzing route types, I realized:&lt;/p&gt;

&lt;p&gt;The only difference between RouteObject and DataRouteObject is the presence of &lt;code&gt;id&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Also:&lt;/p&gt;

&lt;p&gt;If index is true, children must be undefined.&lt;/p&gt;

&lt;p&gt;If index is false, children may exist.&lt;/p&gt;




&lt;h2&gt;
  
  
  So what’s the plan?
&lt;/h2&gt;

&lt;p&gt;To generalize route inference, I decided to extract paths directly from RouteObject.&lt;/p&gt;

&lt;p&gt;I defined my routes like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;appRoutes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...RouteObject[] of children or more.&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;satisfies&lt;/span&gt; &lt;span class="nx"&gt;RouteObject&lt;/span&gt;&lt;span class="p"&gt;[];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I’m not deeply experienced with TypeScript generics,&lt;br&gt;
so I used GPT for parts of the process while debugging errors myself.&lt;/p&gt;

&lt;p&gt;But as inference traversed deeper through &lt;code&gt;children&lt;/code&gt;,&lt;br&gt;
more leading slashes kept getting added.&lt;/p&gt;

&lt;p&gt;To fix this, I checked the presence of &lt;code&gt;element&lt;/code&gt;.&lt;br&gt;
If &lt;code&gt;element&lt;/code&gt; does not exist, the path should be excluded.&lt;/p&gt;

&lt;p&gt;Then I wrote the final route extraction types:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// ... Omitted for brevity (same as your original)&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;AppPaths&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ExtractRoutePath&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;appRoutes&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now path auto-completion works.&lt;/p&gt;

&lt;p&gt;But:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;/* appears in the suggestions&lt;/li&gt;
&lt;li&gt;Dynamic parameters aren’t enforced yet&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I moved on.&lt;/p&gt;




&lt;h2&gt;
  
  
  Extracting and enforcing path parameters
&lt;/h2&gt;

&lt;p&gt;Using conditional types, I extracted parameters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;ExtractParamsFromPath&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Path&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then I implemented:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TypedLink&lt;/li&gt;
&lt;li&gt;useTypedNavigate&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both enforce dynamic parameters at compile time.&lt;/p&gt;

&lt;p&gt;This completed path stability and auto-completion.&lt;/p&gt;




&lt;h2&gt;
  
  
  What about 100+ routes?
&lt;/h2&gt;

&lt;p&gt;With over 100 routes, VSCode’s type inference may lag or even freeze.&lt;/p&gt;

&lt;p&gt;Conceptually, I thought about splitting inference:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/a&lt;/code&gt;, &lt;code&gt;/b&lt;/code&gt;, &lt;code&gt;/c&lt;/code&gt;, &lt;code&gt;/d&lt;/code&gt;, &lt;code&gt;/e&lt;/code&gt; show first&lt;/li&gt;
&lt;li&gt;Once you choose &lt;code&gt;/a&lt;/code&gt;, only its children get inferred&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I didn’t implement this. My current project doesn’t require 100+ routes.&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;There will definitely be bugs, and I’ll fix them little by little.&lt;br&gt;
That’s a problem for tomorrow’s me.&lt;/p&gt;




&lt;h2&gt;
  
  
  Optional Things
&lt;/h2&gt;

&lt;p&gt;This work originally began as an experiment to improve my own navigation&lt;br&gt;
workflow in a production React project. Over time, it became a foundation&lt;br&gt;
for how I think about frontend architecture and type-driven design.  &lt;/p&gt;

&lt;p&gt;I’m revisiting and rewriting it in English to document the approach more&lt;br&gt;
clearly and share it with a wider audience.&lt;/p&gt;

&lt;p&gt;If you want to read the original Korean version of this article, you can find it &lt;a href="https://ash9river.tistory.com/122" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>frontend</category>
      <category>reactrouter</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
