<commit_before># Simple Router mixin-component for twitter flight

You need to mixit it up with one of your components and you will be able to use API to listen routes and and move location to needed path.

## Usage example:
####Component with router
```js
define(['path/to/flight-component','path/to/flight-router'], function(defineComponent, router) {
    return defineComponent(newComponent, router);

    function newComponent() {
        this.index = function() {
            alert('INDEX');
        };
        this.basicHelp = function() {
            alert('HELP');
        };
        this.helpWithParams = function(arg) {
            alert(JSON.stringify(arg));
        };
        this.after('initialize', function() {
            this.defineRoute({
                '/' : 'index', //Simple root listener
                '/help' : 'basicHelp', // Simple URL listener
                '/help/:article/:page' : 'helpWithParams', // Parametrized URL listener
                '/:pageType/:article/:page' : 'helpWithParams', // Will match any url like "/asd/wtf/123"
                '/help?:param=:value&:param2=:value2' : 'helpWithParams' // Will match get params
            });
            var counter = 0;
            var index = [
                '/help',
                '/help/how-to-create-route/page2',
                '/FAQ/navigate/1',
                '/help?get=something&andMore=something:dotted'
            ]
            this.on('click', function() {
                this.navigate(index[counter]);
                counter++;
            });
        });
    }
});
```
####Initializing
```js
require(['path/to/flight-component-with-router'], function(component) {
    document.body.innerHTML = 'Click on body to change url and trigger handler \n \
    Try to press BACK and FORWARD button and your listeners will fire
    ';
    component.attachTo(document.body);
});
```

## Documentation
### this.defineRoute(route, callback);
Route is URL like string, where :variable_like_this will be variable.
Callback must be a string or function. If string provided callback would be taken from 'this' by this string.
Every callback will be fired with 'this' component context.

### this.defineRoute(routesHash);
RoutesHash is hash with route / callback key-value pairs.
Like: this.defineRoute({'/', 'callback'});

### this.navigate(URL, [args]);
URL is url like string. Must start from '/'.
Args is optional object with following params:

```js
    replaceState: Boolean
```
If passed state would not be pushed, but replaced, to save history clean.<commit_msg>fix for example<commit_after># Simple Router mixin-component for twitter flight

You need to mixit it up with one of your components and you will be able to use API to listen routes and and move location to needed path.

## Usage example:
####Component with router
```js
define(['path/to/flight-component','path/to/flight-router'], function(defineComponent, router) {
    return defineComponent(newComponent, router);

    function newComponent() {
        this.index = function() {
            alert('INDEX');
        };
        this.basicHelp = function() {
            alert('HELP');
        };
        this.helpWithParams = function(arg) {
            alert(JSON.stringify(arg));
        };
        this.after('initialize', function() {
            this.defineRoute({
                '/' : 'index', //Simple root listener
                '/help' : 'basicHelp', // Simple URL listener
                '/help/:article/:page' : 'helpWithParams', // Parametrized URL listener
                '/:pageType/:article/:page' : 'helpWithParams', // Will match any url like "/asd/wtf/123"
                '/help?:param=:value&:param2=:value2' : 'helpWithParams' // Will match get params
            });
            var counter = 0;
            var index = [
                '/help',
                '/help/how-to-create-route/page2',
                '/FAQ/navigate/1',
                '/help?get=something&andMore=something:dotted'
            ]
            this.on('click', function() {
                this.navigate(index[counter]);
                counter++;
            });
        });
    }
});
```
####Initializing
```js
require(['path/to/flight-component-with-router'], function(component) {
    document.body.innerHTML = 'Click on body to change url and trigger handler \n \
    Try to press BACK and FORWARD button and your listeners will fire';
    component.attachTo(document.body);
});
```

## Documentation
### this.defineRoute(route, callback);
Route is URL like string, where :variable_like_this will be variable.
Callback must be a string or function. If string provided callback would be taken from 'this' by this string.
Every callback will be fired with 'this' component context.

### this.defineRoute(routesHash);
RoutesHash is hash with route / callback key-value pairs.
Like: this.defineRoute({'/', 'callback'});

### this.navigate(URL, [args]);
URL is url like string. Must start from '/'.
Args is optional object with following params:

```js
    replaceState: Boolean
```
If passed state would not be pushed, but replaced, to save history clean.
{'fraction_non_alphanumeric': 0.1286800545915383, 'fraction_numerical': 0.003119516474946383, 'mean_word_length': 2.480325644504749, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5718937', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1335, 'n_words': 435}