matchPath() function
Home > @rimitive/router > matchPath
matchPath() function
Section titled “matchPath() function”Matches a URL path against a route pattern (exact match)
Supports exact string matching, path parameters using :paramName syntax, and wildcard ’*’ for catch-all
Signature:
matchPath: (pattern: string, path: string) => RouteMatch | nullParameters
Section titled “Parameters”|
Parameter |
Type |
Description |
|---|---|---|
|
pattern |
string | |
|
path |
string |
Returns:
RouteMatch | null
Example
Section titled “Example”import { matchPath } from '@rimitive/router';
// Exact matchmatchPath('/about', '/about');// { path: '/about', params: {} }
// Path parametersmatchPath('/products/:id', '/products/123');// { path: '/products/123', params: { id: '123' } }
// Multiple parametersmatchPath('/blog/:year/:slug', '/blog/2024/hello-world');// { path: '/blog/2024/hello-world', params: { year: '2024', slug: 'hello-world' } }
// WildcardmatchPath('*', '/any/path');// { path: '/any/path', params: {} }
// No matchmatchPath('/about', '/contact');// null