NamedUrlPatterns
Sourceimport { 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.jsimport { NamedUrlPatterns, UrlPattern} from '@prestojs/routing';export default new NamedUrlPatterns({'user-list': new UrlPattern('/users/'),'user-detail': new UrlPattern('/users/:id/'),});// ... elsewhereimport 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 URLnamedUrls.get('user-list')// UrlPattern('/users/')
API
Constructor
new NamedUrlPatterns(urls)
SourceParameter | Type | Description | |
---|---|---|---|
* | urls | {[ urlName: string ]: UrlPattern} |
Methods
get(name)
SourceGet the UrlPattern for the specified name
Parameter | Type | Description | |
---|---|---|---|
* | name | string | Name of pattern to retrieve |
Returns
reverse(name,kwargs,options)
SourceReverse a UrlPattern by it's name
Parameter | Type | Description | |
---|---|---|---|
* | name | string | Name of the pattern to resolve |
* | kwargs | __type | Arguments to replace in pattern, if any |
* | options | ResolveOptions | Extra options to pass through to |
Returns