matchPathPrefix() function
Home > @rimitive/router > matchPathPrefix
matchPathPrefix() function
Section titled “matchPathPrefix() function”Matches a URL path against a route pattern (prefix match for parent routes)
Used for routes with children - matches if the path starts with the pattern
Signature:
matchPathPrefix: (pattern: string, path: string) => RouteMatch | nullParameters
Section titled “Parameters”|
Parameter |
Type |
Description |
|---|---|---|
|
pattern |
string | |
|
path |
string |
Returns:
RouteMatch | null
Example
Section titled “Example”import { matchPathPrefix } from '@rimitive/router';
// Prefix match for parent routesmatchPathPrefix('/products', '/products/123');// { path: '/products/123', params: {} }
// With parametersmatchPathPrefix('/blog/:year', '/blog/2024/hello-world');// { path: '/blog/2024/hello-world', params: { year: '2024' } }
// Root matches everythingmatchPathPrefix('/', '/any/path');// { path: '/any/path', params: {} }
// Exact match still worksmatchPathPrefix('/about', '/about');// { path: '/about', params: {} }
// No match when path is shortermatchPathPrefix('/products/category', '/products');// null