Some Unpoly features like a[up-alias]
let you match any URL with a given pattern.
For this matching Unpoly does not use regular expressions, but the URL pattern format outlined below.
Pass any absolute path or fully qualified URL to only match this exact value:
/users/new
Append an asterisk (*
) to any path to match all URLs with that prefix:
/users/*
Prepend an asterisk to match all URLs with that suffix:
*/edit
You may also infix an asterisk to match URLs with the given prefix and suffix:
/admin/*/edit
To match one of multiple URLs or patterns, separate the alternatives by a space.
The following will match either /users/123
or /account
:
/users/* /account
JavaScript functions that take URL patterns will accept multiple patterns as either a space-separated string or as an array of patterns:
up.layer.open({ acceptLocation: '/users/* /account' })
up.layer.open({ acceptLocation: ['/users/*', '/account'] })
To exclude an URL or pattern, prefix with a minus.
The following will match /users/alice
but not /users/new
:
/users/* -/users/new
It is sometimes useful to capture the value of a wildcard match, e.g. to close an overlay once a location is reached.
The following will capture { name: 'alice' }
from the path /users/alice
:
/users/:name
To only match digits (0-9
), use the dollar symbol:
/users/:$id