# Route Class

Defined in: `js/model/Route.js:9`
Module: model
Parent Module: StructureJS

The Route class is a model that keeps track of a specific route for the Router class.

## Index

Show: Inherited Protected Private Deprecated

### Properties

- callback
- callbackScope
- regex
- routePattern

### Methods

- Route constructor
- _routePatternToRegexp
- match

## Properties

### `callback` Function public

Defined in `js/model/Route.js:94`

The function that should be executed when a request matches the routePattern. The Router class will be using this property.

### `callbackScope` Any public

Defined in `js/model/Route.js:102`

The scope of the callback function that should be executed. The Router class will be using this property.

### `regex` RegExp public

Defined in `js/model/Route.js:85`

The regex representation for the routePattern that was passed into the constructor.

### `routePattern` String public

Defined in `js/model/Route.js:77`

The string pattern you want to have match, which can be any of the following combinations {}, ::, *, ?, "". See below for examples.

There are no properties that match your current filter settings. You can change your filter settings in the index section on this page. index

## Constructor

### `Route`
(

- `routePattern`
- `callback`
- `callbackScope`

)

Defined in `js/model/Route.js:9`

#### Parameters:

- `routePattern` String

  The string pattern you want to have match, which can be any of the following combinations {}, ::, *, ''

- `callback` Function

  The function that should be executed when a request matches the routePattern.

- `callbackScope` Any

  The scope of the callback function that should be executed.

#### Example:

    // Example of adding a route listener and the function callback below.
    let route = new Route('/games/{gameName}/:level:/', this._method, this);

    // The above route would match the string below:
    route.match('/games/asteroids/2/');

## Route Pattern Options:

:optional: The two colons :: means a part of the hash url is optional for the match. The text between can be anything you want it to be.

    let route = new Route('/contact/:name:/', this._method, this);

    // Will match one of the following:
    route.match('/contact/');
    route.match('/contact/heather/');
    route.match('/contact/john/');

{required} The two curly brackets {} means a part of the hash url is required for the match. The text between can be anything you want it to be.

    let route = new Route('/product/{productName}/', this._method, this);

    // Will match one of the following:
    route.match('/product/shoes/');
    route.match('/product/jackets/');

* The asterisk character means it will match all or part of part the hash url.

    let route = new Route('*', this._method, this);

    // Will match one of the following:
    route.match('/anything/');
    route.match('/matches/any/hash/url/');
    route.match('/really/it/matches/any/and/all/hash/urls/');

'' The empty string means it will match when there are no hash url.

    let route = new Route('', this._method, this);
    let route = new Route('/', this._method, this);

    // Will match one of the following:
    route.match('');
    route.match('/');

Other possible combinations but not limited too:

    let route = new Route('/games/{gameName}/:level:/', this._method1, this);
    let route = new Route('/{category}/blog/', this._method2, this);
    let route = new Route('/about/*', this._method3, this);

## Methods

### `_routePatternToRegexp`
(

- `routePattern`

)
RegExp protected

Defined in `js/model/Route.js:115`

Converts the routePattern that was passed into the constructor to a regexp object.

#### Parameters:

- `routePattern` String

#### Returns:

RegExp:

### `match`
(

- `route`

)
Array.

Defined in `js/model/Route.js:139`

Determine if a route matches a routePattern.

#### Parameters:

- `route` String

  The route or path to match against the routePattern that was passed into the constructor.

#### Returns:

Array.:

#### Example:

    let route = new Route('/games/{gameName}/:level:/', this.method, this);
    console.log( route.match('/games/asteroids/2/') );

There are no methods that match your current filter settings. You can change your filter settings in the index section on this page. index