Skip to main content
Factory function to create type-safe path builders that work with auto-generated route type definitions. This is designed to work with the vite-plugin’s generateTypedRoutes option.

Signature

Parameters

Record<string, Record<string, string>>
required
Type parameter representing the mapping of route paths to their parameter types.This is typically auto-generated by the vite-plugin as RouteParams.

Return Type

TypedPaths<TRoutes>
An object with a for() method for building type-safe paths.
function
Build a URL path with type-checked parameters.Parameters:
  • path: string - Route path template (can include ?query suffix)
  • params?: Record<string, string> - Path parameters (required if route has dynamic segments)
Returns: Resolved URL path string

Examples

Basic Setup

Static Routes

Dynamic Routes

Routes with Query Strings

URL Encoding

Catch-all Routes

Type Safety

Usage in Navigation

Programmatic Navigation

Building URLs from Data

TypeScript Types

Implementation Details

Path Parameter Replacement

The for() method replaces dynamic segments in the path template:
  1. Dynamic segments (:paramName): Replaced with the encoded parameter value
  2. Catch-all segments (*paramName): Replaced with the parameter value, encoding each path segment individually while preserving slashes

URL Encoding

  • Dynamic segments (:param) are encoded using encodeURIComponent(), which encodes the entire value including slashes
  • Catch-all segments (*param) split the value on /, encode each segment individually, then rejoin with / to preserve path structure

Notes

  • This function is designed to work with auto-generated route types from the vite-plugin
  • Path parameters are automatically URL-encoded
  • Query strings can be included in the path template using ? syntax
  • TypeScript will enforce that all required parameters are provided with correct types
  • Empty parameter objects ({}) indicate routes with no dynamic segments