'use strict';

var Router = require('routr'),
    querystring = require('querystring'),
    router,

// The single routing action can be used at both server/client side.
routingAction = function () {
    var path = this.getStore('page').get('url.pathname'),
        route = router.getRoute(path);

    if (!route) {
        return this.rejectPromise('no matched route');
    }

    this.dispatch('UPDATE_ROUTING', {
        name: route.name,
        params: route.params
    });

    return this.executeAction(route.config.action);
},

getURL = function (name, param, query) {
    var qs = querystring.encode(query);
    return router.makePath(name, param) + (qs ? '?' + qs : '');
};

module.exports = function (config) {
    router = new Router(config);

    return {
        routing: routingAction,
        getURL: getURL,
        routeToURL: require('fluxex/extra/routeToURL')
    };
};

module.exports.mixin = {
    getURL: function (name, param, query) {
        return this._getContext().getURL(name, param, query);
    }
};

@@ -612,20 +612,24 @@
 ery)
-;
+,
 %0A    
-return
+    path =
  rou
@@ -653,16 +653,141 @@
 , param)
+;%0A%0A    if (!path) %7B%0A        throw new Error('Can not generate URL by route name: %5C'' + name + '%5C' !');%0A    %7D%0A%0A    return path
  + (qs ?

throw error when not found