Skip to content

Support named typed-path nodes for index routes #574

Description

@brenelz

Summary

Allow an index route such as / to expose a named typed-path node, so applications can write paths.index instead of calling the root builder with paths().

Current behavior

const Router = createRouter({
  routes: [
    { path: "/", component: Home },
    { path: "/about", component: About },
  ],
});

const { paths } = Router;

paths();       // "/"
paths.about;   // "/about"
paths.index;   // TypeScript error; the runtime proxy represents "/index"

Static path nodes have descriptive property names, but the root/index route is represented by calling the path proxy itself. This makes a navigation vocabulary such as paths.index, paths.about, and paths.settings impossible without maintaining a separate application-level alias map.

Desired API

A route should be able to opt into a named path node whose value still comes from its actual path:

paths.index; // "/"

The exact route configuration API is open for discussion. Collision-safe possibilities include explicit naming:

{ path: "/", name: "index", component: Home }

or explicit index metadata:

{ path: "/", index: true, component: Home }

An explicit convention seems preferable to globally treating .index as a no-op segment, since applications may have a real /index route.

Design considerations

  • Keep the runtime proxy and RoutePaths inference aligned.
  • Preserve access to literal /index routes without ambiguity.
  • Consider nested index routes, for example paths.users(id).index producing /users/:id.
  • Preserve base-path and hash-history rendering behavior.
  • Keep paths() working for backward compatibility.
  • Ideally allow names other than index if the underlying feature is named routes rather than an index-only special case.

Motivation

This keeps links, redirects, and navigation calls on one typed, semantic path vocabulary without requiring manually maintained aliases:

<a href={paths.index}>Home</a>
<a href={paths.about}>About</a>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions