Skip to content

Syntax

Fixed segments

example.ts
ts
import { RouteMatcherBuilder } from 'route-peek';

const matcher = new RouteMatcherBuilder()
  .add('/users') 
  .build();

Dynamic segments

example.ts
ts
import { RouteMatcherBuilder } from 'route-peek';

const matcher = new RouteMatcherBuilder()
  .add('/users/{id}') 
  .build();

Using regular expressions

example.ts
ts
import { RouteMatcherBuilder } from 'route-peek';

const matcher = new RouteMatcherBuilder()
  .add('/users/{id:\\d+}') 
  .build();

Multiple elements

example.ts
ts
import { RouteMatcherBuilder } from 'route-peek';

const matcher = new RouteMatcherBuilder()
  .add('/static/{fileName:[a-z]+}-{hash:[a-zA-Z0-9]+}.{ext:js|css}') 
  .build();

Wildcard segments

example.ts
ts
import { RouteMatcherBuilder } from 'route-peek';

const matcher = new RouteMatcherBuilder()
  .add('/users/*') 
  .build();

Modifiers

Optional segment

example.ts
ts
import { RouteMatcherBuilder } from 'route-peek';

const matcher = new RouteMatcherBuilder()
  .add('/{page}?') 
  .build();

Zero and more

example.ts
ts
import { RouteMatcherBuilder } from 'route-peek';

const matcher = new RouteMatcherBuilder()
  .add('/{page}*') 
  .build();

One and more

example.ts
ts
import { RouteMatcherBuilder } from 'route-peek';

const matcher = new RouteMatcherBuilder()
  .add('/{page}+') 
  .build();

Released under the MIT License.