Skip to main content

Summary

Returns a path with params interpolated into the pattern. Useful for programmatically creating URLs from route patterns and parameter values. This is the inverse of path matching - instead of extracting params from a path, it creates a path from params.

Signature

Parameters

string
required
The path pattern containing parameter placeholders. Parameters are denoted with :paramName syntax.Examples:
  • /users/:userId
  • /posts/:postId/comments/:commentId
  • /files/*
object
An object mapping parameter names to their values. Parameter values should be strings or null.Required parameters must have non-null values. Optional parameters can be null or undefined.

Returns

string
The generated path with all parameters interpolated.

Examples

Basic parameter interpolation

Multiple parameters

Optional parameters

Wildcard paths

No parameters

Common Use Cases

Programmatic navigation

API URL construction

Dynamic breadcrumbs

Batch URL generation

Form redirects

Type Safety

TypeScript automatically infers required parameters:

Parameter Encoding

Parameter values are automatically URL-encoded:

Edge Cases

Missing required parameters

Null vs undefined

Extra parameters

Leading/trailing slashes

Pattern Examples

Simple dynamic route

Nested dynamic routes

With file extensions

With hyphens and underscores

Performance

generatePath is a fast, synchronous operation suitable for use in render functions:

Notes

  • Parameter names must match exactly (case-sensitive)
  • Parameters are URL-encoded automatically
  • Required parameters throw if missing
  • Optional parameters (:param?) can be omitted
  • Wildcard segments (*) capture remaining path
  • Extra parameters in the object are ignored
  • Empty string parameters are treated as values (not omitted)