zordius/fluxex

View on GitHub
examples/02-routing/actions/routing.js

Summary

Maintainability
A
0 mins
Test Coverage
'use strict';

var page = require('./page'),
    router = require('routes')();

router.addRoute('/product/:id', ['product', page.product]);
router.addRoute('/main', ['top', page.main]);

// The single routing action can be used at both server/client side.
module.exports = function () {
    var path = this.getStore('page').getPath();
    var match = router.match(path);

    if (!match) {
        return Promise.reject(new Error('no matched route for url: ' + path));
    }

    this.dispatch('UPDATE_ROUTING', {
        name: match.fn[0],
        params: match.params
    });

    return this.executeAction(match.fn[1]);
};