/**
 * @desc routes
 * @author awwwesssooooome <chengpengcp9@gmail.com>
 * @date 2015-10-12
 */

'use strict';

/**
 * Module dependencies
 */
import React from 'react';
import {Route} from 'react-router';
import App from '../app/components/App.react';
import Index from '../app/components/Index.react';
//import Stats from './components/Stats';
//import Character from './components/Character';
//import CharacterList from './components/CharacterList';
//import AddCharacter from './components/AddCharacter';

// example
//export default (
//  <Route handler={App}>
//    <Route path='/' handler={Home} />
//    <Route path='/stats' handler={Stats} />
//    <Route path='/characters/:id' handler={Character} />
//    <Route path='/add' handler={AddCharacter} />
//    <Route path=':category' handler={CharacterList}>
//      <Route path=':race' handler={CharacterList}>
//        <Route path=':bloodline' handler={CharacterList} />
//      </Route>
//    </Route>
//  </Route>
//);
export default (
    <Route handler={App}>
        <Route path='/' handler={Index} />
    </Route>
);

/**
 * @desc routes
 * @author awwwesssooooome <chengpengcp9@gmail.com>
 * @date 2015-10-12
 */

'use strict';

/**
 * Module dependencies
 */
import React from 'react';
//import {Router, Route} from 'react-router'; // not work, but api said ok
import Router from 'react-router';
import {Route} from 'react-router';
import swig from 'swig'; 
import App from '../app/components/App.react';
import Index from '../app/components/Index.react';

import pkg from '../package.json';

export default ((app) => {
    let routes = (
        <Route handler={App}>
            <Route path='/' handler={Index} />
        </Route>
    );

    app.use((req, res) => {
        Router.run(routes, req.path, (Handler) => {
            let html = React.renderToString(React.createElement(Handler));
            let page = swig.renderFile('./app/views/index.html', { html: html, pkg: pkg });
            res.send(page);
        });
    });
});

remove example