NamedUrlPatterns

Source
import { NamedUrlPatterns } from "@prestojs/routing";

Define a lookup from a name to a URL pattern.

Provides shortcut to resolve a pattern based on name.

Usage:

// urls.js
import { NamedUrlPatterns, UrlPattern} from '@prestojs/routing';
export default new NamedUrlPatterns({
'user-list': new UrlPattern('/users/'),
'user-detail': new UrlPattern('/users/:id/'),
});
// ... elsewhere
import namedUrls from '../urls.js';
namedUrls.resolve('user-list');
// /users/
namedUrls.resolve('user-detail', { id: 5 }, { query: { showAddresses: true }});
// /users/5/?showAddresses=true
// Or to get the pattern direclty without resolving URL
namedUrls.get('user-list')
// UrlPattern('/users/')

API

new NamedUrlPatterns(urls)

Source
ParameterTypeDescription
*urls{[ urlName: string ]: UrlPattern}

Methods

Get the UrlPattern for the specified name

ParameterTypeDescription
*namestring

Name of pattern to retrieve

Reverse a UrlPattern by it's name

ParameterTypeDescription
*namestring

Name of the pattern to resolve

*kwargs__type

Arguments to replace in pattern, if any

*optionsResolveOptions

Extra options to pass through to UrlPattern.resolve

string

Properties